Execute a JavaScript when the browser window is resized: - Javascript DOM Event

Javascript examples for DOM Event:onresize

Description

Execute a JavaScript when the browser window is resized:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body onresize="myFunction()">

<p id="demo"></p>

<script>
function myFunction() {//from  w w w  .j ava  2s .c  om
    var w = window.outerWidth;
    var h = window.outerHeight;
    var txt = "Window size: width=" + w + ", height=" + h;
    document.getElementById("demo").innerHTML = txt;
}
</script>

</body>
</html>

Related Tutorials