onresize event
Definition and usage
The onresize event occurs when the browser window is resized.
Tip:To get the size of an element, use clientWidth, clientHeight,innerWidth,innerHeight,outerWidth,outerHeightand offsetWidth and/or offsetHeight properties.
Instance
Example 1
Execute JavaScript when adjusting the browser window size:
<body onresize="myFunction()">
Example 2
Use the addEventListener() method to attach the "resize" event to the window object:
window.addEventListener("resize", myFunction);
Syntax
In HTML:
<element onresize="myScript">
In JavaScript:
object.onresize = function(){myScript};
In JavaScript, use the addEventListener() method:
object.addEventListener("resize", myScript);
Note:Internet Explorer 8 or earlier versions do not support addEventListener() method.
Technical details
Bubble: | Not supported |
---|---|
Cancelable: | Not supported |
Event type: | If generated from the user interfaceUiEvent. Otherwise Event. |
Supported HTML tags: | <body> |
DOM version: | Level 2 Events |
Webbläsarstöd
Händelser | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
onresize | Stöd | Stöd | Stöd | Stöd | Stöd |