How to tell if JS Windows8 metro app is visible or

2020-03-07 11:44发布

I am trying to create an app which does some work when it becomes visible, and does other work when it goes away. This is typically accomplished with the page visibility api (http://css.dzone.com/articles/using-html5s-pagevisibility) but this is not currently supported in windows 8: http://msdn.microsoft.com/en-us/library/ie/hh673553(v=vs.85).aspx

There are callbacks onactivated and oncheckpoint but these are for the process lifecycle and are not necessarily related to app visibility. Specifically, an app can go to the background for quite some time before it is suspended.

Any help would be appreciated.

-- Henry

2条回答
对你真心纯属浪费
2楼-- · 2020-03-07 12:33

I think you want the visibilitychange event. See the Document documentation here. More on application lifecycle events here.

App visibility

When the user switches from your app to another app, your app is no longer visible but remains in the running state until Windows can suspend it (for about 10 seconds). If the user switches away from your app but activates or switches back to it before Windows can suspend it, the app remains in the running state.

Your app doesn't receive an activation event when app visibility changes, because the app is still running. Windows simply switches to and from the app as necessary. If your app needs to do something when the user switches away and back, it can handle the VisibilityChanged | msvisibilitychange event.

The visibility event is not serialized with the resume or activation events. Don't assume that these events come in a particular order.

查看更多
时光不老,我们不散
3楼-- · 2020-03-07 12:33

If you want to track app focus switches you could use window.onblur and window.onfocus. Especially in multimon environments that's helpful.

查看更多
登录 后发表回答