admin管理员组文章数量:1323348
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?
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?
- Very interesting find- confirmed Google Chrome 6.0.472.55 – Chris Laplante Commented Sep 15, 2010 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 Commented Sep 15, 2010 at 0:28
- I couldn't reproduce. Chrome 7.0.517.5 dev on Mac OS X – esqew Commented Sep 15, 2010 at 0:35
4 Answers
Reset to default 3The 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.
Well how about that? Sounds like a bug. I would guess that onresize
is listened-for by a bination of behaviors, probably new data about the page size that, for whatever reason, is ing 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.
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.
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).
版权声明:本文标题:javascript - Why does the 'window.resize' event fire when changing tabs in Chrome (6.0.472.55)? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742126635a2421973.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论