Welcome to WebmasterWorld Guest from 54.198.46.95

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)



Hello,

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 Jul 7, 2011 (gmt 0)



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

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



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 Jul 7, 2011 (gmt 0)



The following link explains the problem better than I can:

[snook.ca...]
 

Featured Threads

Hot Threads This Week

Hot Threads This Month