The onresize
property of the GlobalEventHandlers
interface is an event handler that processes resize
events.
The resize
event fires after the window has been resized.
The onresize
property of the GlobalEventHandlers
interface is an event handler that processes resize
events.
The resize
event fires after the window has been resized.
window.onresize = functionRef;
functionRef
is a function name or a function expression. The function receives a FocusEvent
object as its sole argument.
<p>Resize the browser window to fire the <code>resize</code> event.</p> <p>Window height: <span id="height"></span></p> <p>Window width: <span id="width"></span></p>
const heightOutput = document.querySelector('#height'); const widthOutput = document.querySelector('#width'); function resize() { heightOutput.textContent = window.innerHeight; widthOutput.textContent = window.innerWidth; } window.onresize = resize;
Specification |
---|
HTML Standard # handler-onresize |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
onresize |
34 |
79
12-79
In EdgeHTML versions of Edge, this handler was only supported on the
Window API. |
38 |
4
In Internet Explorer, this handler was only supported on the
Window API. |
21 |
10.1 |
37 |
34 |
38 |
21 |
10.3 |
2.0 |
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onresize