Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
365 views
in Technique[技术] by (71.8m points)

javascript - Firefox extension: check if window is minimized

I'm trying to keep track of the state of a Firefox window ("maximized", "minimized", "normal", "fullscreen"; see here). However, whatever I've tried, I never get to see the minimized event; the others doing fine. For example, if I add listeners to the window such as

window.addEventListener("activate", function(event) { dump("activate " + window.windowState + " " + window.screenX + " " + window.screenY + "
"); }, false);
window.addEventListener("deactivate", function(event) { dump("deactivate " + window.windowState + " " + window.screenX + " " + window.screenY + "
"); }, false);
window.addEventListener("resize", function(event) { dump("resize " + window.windowState + " " + window.screenX + " " + window.screenY + "
"); }, false);

I never see 2 as the window.windowState (2 = STATE_MINIMIZED). I've tried a workaround using screenX and screenY, but that doesn't help. When I minimize the window the deactivate - not the resize - event fires with window.windowState being 3 (STATE_NORMAL) and the old screenX/screenY values.

Is there any way to detect when the Firefox window is being minimized? I'm at my wits' end.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should be listening to the sizemodechange event. That's the event firing after the window is minimized or maximized. The resize event doesn't fire for window minimization because technically the window isn't resized - it is hidden. And the deactivate event likely fires before the window is minimized, when it still has the normal state (I didn't check however).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...