well, i kind of stumbled with this for a few minutes, but if you’re trying to capture the resize event, you have to attach the listener to the WINDOW object and NOT the body.
This is WEIRD because the way w3schools has it, they attach it seemingly to the body.
<body onresize=" alert('resized'); "> </body>
That method actually works. But if you need to dynamically attach/detach the resize event handler, then you’ll need to use javascript to do it.
So, here’s how you do it:
window.onresize = function() { alert('resized'); };
And here’s how you DON’T do it:
document.body.onresize/*WRONG!!*/ = function() { alert('resized'); };
There’s a nice forum post @ bytes.com with some weird code.
5 Comments
You are right…but what does this have to do with Prototype?
:) yeah. well, i originally had posted this using prototype js code.
then i edited the post using normal js (looks simpler in this instance!) and forgot to change the title.
You can find a real example of how to se the onresize even with prototype on my blog at http://robcos.com/onresize-event-and-prototype/
Thank you very much! I had the same problem, in few seconds I straightened it out!
I’m guessing this overwrites any code that was previously assigned to the onresize event. Is there any way to add further code to this event without overwriting what was there before?
2 Trackbacks/Pingbacks
[…] since you will overwrite any other event listeners that can have been add by other libraries (Bobobobo has a bad example) Tags: Javascript, listener, onresize, prototype, resize event, window| Posted […]
window.resize + OpenLayers = full-screen maps…
A persistent feature request for our GIS facilities management map has been “full screen mode.” So, today, I sat down to tie together browser resize and OpenLayers map sizing. I wasn’t sure off-hand if resize was a window, document, or b…