开发者

Javascript - Maximize and tab switching events are not called in Firefox using focus

I am facing a weird behavior and I need some help..

I am trying to catch every tab switching event and every maximize event (meaning: whenever my window is shown), using the following code:

window.addEventListener("focus", function (e) { this.foo(e); }, false);
window.document.addEventListener("focus", function (e) { this.foo(e); }, false);

However, It doesn't catch maximize event! How can I tell whenever a user maximizes my window after a minimize?

Also, it seems redundant to me to have both window.addEventListener("focus") and window.document.addEventListener("focus") but I found out that when switching 开发者_如何学编程between tabs, the selected document it focuses on might not be the content I'm interested in, so that's why I'm using window.focus.... However it doesn't always fire this event for window, so I must listen to both focuses... What do you think?

Can you please help me understand where's my problem? I need to create an event that fires on every tab switching \ maximize - and for every document inside my window so that it'll process my content?

Thank a lot, Nili


You can use window.onresize event, if window.outerHeight === screen.availHeight && window,outerWidth === screen.availWidth, it's maximized.

But outerHeight/Width DOES NOT sopport IE8-, see http://www.javascriptkit.com/domref/windowproperties.shtml

Updated: For IE8- hacks: If you can sure the user can accept to maximize window size to maximum, you can use window.resizeTo(screen.availWidth, screen.availHeight) and record the document.documentElement.clientWidth and document.documentElement.clientHeight to compare if it's maximized for later.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜