Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

me: 1, IE: 0 - window.onresize() triggers document.body.onresize()

A simpler solution than any other I've seen...

11:25 am on Jul 7, 2011 (gmt 0)

New User

joined:June 9, 2011
votes: 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 :)
11:32 am on July 7, 2011 (gmt 0)

New User

joined:June 9, 2011
votes: 0

Bunghole. The above is total bunkum. Didn't test properly. Sorry.
3:51 pm on July 7, 2011 (gmt 0)

Senior Member

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

joined:Nov 28, 2004
votes: 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?
4:10 pm on July 7, 2011 (gmt 0)

New User

joined:June 9, 2011
votes: 0

The following link explains the problem better than I can:


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members