MirrorMirror
MirrorMirror

Reputation: 188

ie8 onresize event, firing twice

in my html:

<body onresize="doSomething();">

I have this in my javascript:

function doSomething() {
    alert(1);
    // it doesn't actually have alert(1), but this is just for demonstration
}

When i resize the browser window ( by double clicking its title ), the event fires twice in IE8, thus messing up with the function.

Does anyone know why and how it can be avoided ? thanks in advance!

Upvotes: 0

Views: 1014

Answers (2)

Eugen Rieck
Eugen Rieck

Reputation: 65342

You will find, that if you "resize around" a browser window by randomly moving around the drag area in the lower right corner, the onresize event fires repeatedly.

The point is, that it is quite debateable, what constitutes a window resize. You will have to accept, that this is wildly different between browsers and OSes.

Recipies to handle that include cancelling if set, then setting a timer (window.setTimeout) on the resize event and doing the real resize work when the timer fires.

If your onresize is not too expensive, you should just create it in a way, that is unconcerned by repeated calling.

Upvotes: 3

Loris
Loris

Reputation: 491

This is a duplicate of Window resize event fires twice in jQuery. The onresize event fires when the window is resized however can fire multiple times.

Upvotes: 2

Related Questions