homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

me: 1, IE: 0 - window.onresize() triggers document.body.onresize()
A simpler solution than any other I've seen...

Msg#: 4336292 posted 11:25 am on Jul 7, 2011 (gmt 0)


I don't know how much use this will be to people, but just in case...

If you've struggled with CSS expressions to force IE5/6 to respect max-width, no doubt many of you will have resorted to hooking the onresize() event.

The problem is, IE5 and 6 (Windows) fires both window.onresize() and document.body.onresize() whenever you resize the browser window. This can result in ugly flickering at best. At worst (if you're doing more than just max-width trickery), all sorts of horrible things can happen.

I've seen a number of 'solutions' involving using global variables to keep track of the window's old size, and comparing them to the new size, to decide whether or not to call your custom onresize() function.

This is nonsense. Iv'e found it's far simpler to stick this in a conditionally-commented script at the bottom of your <body>:

document.body.onload = function() { myFunction(); }
window.onresize = function() { myFunction(); }
document.body.onresize = function() { }

HTH :)



Msg#: 4336292 posted 11:32 am on Jul 7, 2011 (gmt 0)

Bunghole. The above is total bunkum. Didn't test properly. Sorry.


WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 4336292 posted 3:51 pm on Jul 7, 2011 (gmt 0)

I don't get it, how can you resize the window without resizing the body? And why would you need actions on one and not the other?


Msg#: 4336292 posted 4:10 pm on Jul 7, 2011 (gmt 0)

The following link explains the problem better than I can:


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved