View Full Version : event for resizing window
tyler jones
08-06-2003, 01:31 PM
Is there a way that I can fire a function when the browser window is resized? Thanks.
requestcode
08-06-2003, 01:38 PM
You could use the onResize function in the body tag like this:
<body onResize="some_function()">
brothercake
08-06-2003, 01:40 PM
It's not quite as simple as that if you want it fully x-browser - onresize potentially exposes a bug in ns4, and doesn't work at all in opera 5 or 6, or konqueror 2 ...
You're probably not bothered about your script working in them, but you need to be aware of the ns4 issue if if you're gonna reload onresize, because it can cause a crash.
Have a look at this http://www.brothercake.com/scripts/resize.php which shows the various approaches to combine; that example does reload the page, but you can equally do something else with the event.
tyler jones
08-06-2003, 02:52 PM
The onResize will work fine for my purposes. Thanks a lot. However, how do I get the new size of the window? screen.width is returning 800 no matter what size I resize the browser to.... so I'm obviously using the wrong property and I can't remember what the correct way is. Thanks.
Cymru
08-06-2003, 03:11 PM
Use window.innerWidth/Height for Netscape (including 6.0+).
Use document.body.clientWidth/Height for IE and Opera.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.