Windows store app: detecting if your app is visible or not

I wanted to find out if my game app was visible or not because I wanted to pause the game if the user Alt-Tabbed or pressed the windows key. I found the following article on stack overflow that explained that you can listen to the msvisibilitychange event to detect changes like this:

document.addEventListener("msvisibilitychange", function ()
{
    //Pause function
});

However Microsoft doesn’t seem to be very happy with you putting to much code in this event as it might cause a “less fluid user experience”. I just pause the game there though 🙂

One thought on “Windows store app: detecting if your app is visible or not

  1. This is not wrong, but incomplete. Because this event can handle pause and resume, in the function, if “document.visibilityState” is “hidden”, application is paused. But if “document.visibilityState” is “visible”, application is resumed. 😉

Leave a Reply