revision:
The onresize event occurs when the browser window has been resized.
Supported HTML tags: <body>
To get the size of an element, use the "clientWidth", "clientHeight", "innerWidth", "innerHeight", "outerWidth", "outerHeight", "offsetWidth" and/or "offsetHeight" properties.
<element onresize="script"></element>
script: this attribute contains a "single value script", which works when the onreset event attribute is called.
Try to resize the browser window to display the windows height and width.
<body onresize="sizeFunction()"> <p class="spec">Try to resize the browser window to display the windows height and width.</p> <p class="spec" id="demo_AA"></p> <script> function sizeFunct() { var w = window.outerWidth; var h = window.outerHeight; var txt_A = "Window size: width=" + w + ", height=" + h; document.getElementById("demo_AA").innerHTML = txt_A; } </script>
This example uses the addEventListener() method to attach a "resize" event on the window object.
Try to resize the browser window.
Window resized 0 times.
<p class="spec">This example uses the addEventListener() method to attach a "resize" event on the window object.</p> <p class="spec">Try to resize the browser window.</p> <p class="spec">Window resized <span id="demo+AA">0</span> times.</p> <script> window.addEventListener("resize", windowResize); var x = 0; function windowResize() { var txt_B = x += 1; document.getElementById("demo+A").innerHTML = txt_B; } </script>