The GlobalEventHandlers.onresize property contains an EventHandler triggered when a resize event is received.
window.onresize = funcRef;
funcRef is a reference to a function.window.onresize = doFunc;
<html>
<head>
<title>onresize test</title>
</head>
<body>
<p>Resize the browser window to fire the resize event.</p>
<p>Window height: <span id="height"></span></p>
<p>Window width: <span id="width"></span></p>
<script type="text/javascript">
var heightOutput = document.querySelector('#height');
var widthOutput = document.querySelector('#width');
function resize() {
heightOutput.textContent = window.innerHeight;
widthOutput.textContent = window.innerWidth;
}
window.onresize = resize;
</script>
</body>
</html>
The resize event is fired after the window has been resized.
| Specification | Status | Comment |
|---|---|---|
| HTML Living Standard The definition of 'onresize' in that specification. | Living Standard |
| Desktop | ||||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
| Basic support | 45 | Yes | Yes | Yes | 32 | Yes |
| Mobile | |||||||
|---|---|---|---|---|---|---|---|
| Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
| Basic support | 45 | 45 | Yes | Yes | 32 | Yes | Yes |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onresize