Javascript DOM onresize Event via addEventListener() method

Introduction

In JavaScript, using the addEventListener() method:

object.addEventListener("resize",
       myScript);

This example uses the addEventListener() method to attach a "resize" event on the window object.

View in separate window

<!DOCTYPE html>
<html>
<body>
<p>Try to resize the browser window.</p>

<p>Window resized <span id="demo">0</span> times.</p>

<script>
window.addEventListener("resize", myFunction);

var x = 0;/* w w w . j a  v  a 2 s.  c  o m*/
function myFunction() {
  var txt = x += 1;
  document.getElementById("demo").innerHTML = txt;
}
</script>

</body>
</html>
Bubbles: No
Cancelable: No
Event type: UiEvent if generated from a user interface, Event otherwise
Supported HTML tags: <body>



PreviousNext

Related