views:

12050

answers:

5

What is the correct (modern) method for tapping into the window resize event that works in Firefox, WebKit, and IE?

and can you turn both scrollbars on/off?

+3  A: 

Since you are open to jQuery, this plugin seems to do the trick.

Paolo Bergantino
+1 and Answer. Good find.
tyndall
+8  A: 

$(window).bind('resize', function () {

alert('resize');

});

fts
Thanks. That did the trick for me.
pelms
+11  A: 

jQuery has a built-in method for this:

$(window).resize(function () { /* do something */ });

For the sake of UI responsiveness, you might consider using a setTimeout to call your code only after some number of milliseconds, as shown in the following example, inspired by this:

function doSomething() {
    alert("I'm done resizing for the moment");
};

var resizeTimer;
$(window).resize(function() {
    clearTimeout(resizeTimer);
    resizeTimer = setTimeout(doSomething, 100);
});
Andrew Hedges
A: 

You can use resizeMyBrowser. Hope this helps. http://resizeMyBrowser.com

Sam
A: 

Does anyone have a clue on how I could do this from within an iFrame? I tried for example setting:

$(window.top).bind('resize', function () { alert('hi'); });

I have also tried with top.document and other combinations, but none of them seems to work... The problem is that $(window) refers to the iframe and not the browser window.

Does anyone have a solution for this?

Kostas