Take the 2-minute tour ×

I came across an interesting bug feature tonight when writing a handler for window.onresize in Chrome (the latest version 6.0.472.55). First open two tabs, then in the first tab open this jsFiddle.

Resize the window at will and the dialog box works as expected. Now, try switching to the 2nd tab -_-. Why is resize firing when the tab is changed? Could someone provide insight/more details if I need to file a bug?

share|improve this question
Very interesting find- confirmed Google Chrome 6.0.472.55 –  Chris Laplante Sep 15 '10 at 0:23
I think it's a bug: it doesn't fire on tab change in Chrome 6.0.472.55 on Linux (Ubuntu 10.4) –  Utaal Sep 15 '10 at 0:28
I couldn't reproduce. Chrome 7.0.517.5 dev on Mac OS X –  esqew Sep 15 '10 at 0:35

4 Answers 4

up vote 2 down vote accepted

The bug has been filed with Google. For the time being, I've just ignored it since my actual onresize handler doesn't display alert boxes.

share|improve this answer

Well how about that? Sounds like a bug. I would guess that onresize is listened-for by a combination of behaviors, probably new data about the page size that, for whatever reason, is coming in when a tab is focused.

In the version I use on Windows, 5.0.375.127, it doesn't happen, but if I actually resize the window, the resize event fires twice.

Knowing it's there, you can take a step to defeat it (that Google ought to do for you eventually). Wrap an if statement around your handler that checks for an actual change in the clientHeight or clientWidth if you need something to happen only if the event (as we understand it) actually occurs.

share|improve this answer

Without a working knowledge of how Chrome handles tab switching and page rendering, my guess is as good (or bad, depending how you look at it) as the next guy's. I would guess that rerendering the page, or reloading the already rendered page if it caches it, triggers the onresize event. This is what happens when the tab is switched. Following my theory, I would guess that Chrome doesn't trigger the resize event on initial page view because it has been designed not to. But again, as I don't know how Chrome handles tab switching internally, this is just speculation (food for thought).

share|improve this answer

From the bug report:

When using Dev Tools in splitview and switching to a Tab without Dev Tools opened in split, the resize-Event will be fired.

So, if the next Tab doesn't have the same window size, resize() will be fired.

share|improve this answer

Your Answer


