Javascript/Detect Window Resize

Advertisement


Question
Hi. How do I detect if the browser window has been resized? I placed this code in my body tag:

onResize="alert('Thanks For Resizing');"

but doesn't work. I'm using IE6 on WinXP PC. Any suggestions? I appreciate your help.

Thanks in advance,
Mark

Answer
Hi there Mark,

To be honest, I'm not sure why that's not working for you.  When I try that - it works fine for me and I get the alert.  I am also using IE6 on WinXP.  My body tag looks like this:

<body onResize="alert('body resize');">


There is another way to do the same thing, and perhaps that method may work for you when this one doesn't for some reason.  Put a script tag in your page like this:

<script language="Javascript">
document.body.onresize = function (){
 alert("Thanks for resizing!");
}
</script>

That method also works for me, and it may work for you too.

take care,
Randy L. Taylor

Javascript

All Answers


Answers by Expert:


Ask Experts

Volunteer


Randy L. Taylor

Expertise

I can answer advanced questions concerning most aspects of web programming including HTML, DHTML, DOM, JavaScript, Cookies, Internet Explorer, and CSSs. I can answer basic questions concerning XML and ActiveX. I can also answer questions concerning Regular Expressions, logical design algorithms, and Object Oriented Programming.

Experience


Past/Present clients
Upp Business Systems, LLC
Headquarters Standard Systems Group, USAF

©2012 About.com, a part of The New York Times Company. All rights reserved.