Execute a JavaScript when the browser window is resized:
More "Try it Yourself" examples below.
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.
Event | |||||
---|---|---|---|---|---|
onresize | Yes | Yes | Yes | Yes | Yes |
In HTML:
In JavaScript:
In JavaScript, using the addEventListener() method:
Note: The addEventListener() method is not supported in Internet Explorer 8 and earlier versions.
Bubbles: | No |
---|---|
Cancelable: | No |
Event type: | UIEvent |
Supported HTML tags: | <body> |
DOM Version: | Level 2 Events |
Using the addEventListener() method to attach the "resize" event on the window object.