Latest web development tutorials
 

onresize Event

< Event Object

Example

Execute a JavaScript when the browser window is resized:

<body onresize="myFunction()">
Try it Yourself »

More "Try it Yourself" examples below.


Definition and Usage

The onresize event occurs when the browser window has been resized.

Tip: To get the size of an element, use the clientWidth, clientHeight, innerWidth, innerHeight, outerWidth, outerHeight, offsetWidth and/or offsetHeight properties.


Browser Support

Event
onresize Yes Yes Yes Yes Yes

Syntax

In HTML:

<element onresize="myScript">
Try it Yourself »

In JavaScript:

object.onresize=function(){myScript};
Try it Yourself »

In JavaScript, using the addEventListener() method:

object.addEventListener("resize", myScript);
Try it Yourself »

Note: The addEventListener() method is not supported in Internet Explorer 8 and earlier versions.


Technical Details

Bubbles: No
Cancelable: No
Event type: UIEvent
Supported HTML tags: <body>
DOM Version: Level 2 Events

Examples

More Examples

Example

Using the addEventListener() method to attach the "resize" event on the window object.

window.addEventListener("resize", myFunction);
Try it Yourself »

< Event Object