Wednesday, January 8, 2014

listening for the browser to resize in JavaScript

This suggests one may sniff for the browser being resized in plain Jane JavaScript like so:

window.addEventListener('resize', function(event){
   
// do stuff here
});

 
 

I researched this some for this but ended up doing things the dojo way and not blogging of the normal path to success. The stuff at the first link I give also has a link over to this which shows a working example using the following code:

go();
window.addEventListener('resize', go);
 
function go(){
   document.querySelector('.width').innerText = document.documentElement.clientWidth;
   document.querySelector('.height').innerText = document.documentElement.clientHeight;
}

No comments:

Post a Comment