Execute a JavaScript when the browser window is resized:
Try to resize the browser window to display the windows height and width.
<!DOCTYPE html> <html> <body onresize="myFunction()"> <p id="demo"></p> <script> function myFunction() {//from www. j ava2 s . co m var w = window.outerWidth; var h = window.outerHeight; var txt = "Window size: width=" + w + ", height=" + h; document.getElementById("demo").innerHTML = txt; } </script> </body> </html>
The onresize event occurs when the browser window has been resized.
Bubbles: | No |
---|---|
Cancelable: | No |
Event type: | UiEvent if generated from a user interface, Event otherwise |
Supported HTML tags: | <body> |