Handle window resize event - Javascript DOM

Javascript examples for DOM:Element addEventListener

Description

Handle window resize event

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/* w ww  .jav a 2 s.  c o m*/
function resizeHandler(e) {
    console.log(e.type + ' triggered.');
}
window.addEventListener('resize', resizeHandler);
var resizeEvent = new Event('resize');
window.dispatchEvent(resizeEvent);
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials