Is there a way to see the browser window is minimized when the user switches to another window on the iphone?
Is there a way to see the browser window minimizing when the user switches to another window on the IPhone ? It's the same when the browser window becomes inactive, switching to any other application.
I tried to bind to jQuery onfocus, onblur events ( $(window).blur(...);
) but didn't get callbacks.
Thank!
source to share
I think the closest to what you are looking for, this , and events . In tests I did in iOS 5.1, when switching to another app from Mobile Safari after double clicking the home button, the event seemed to fire just before the app actually switched, whereas if I pressed the home button only once, go to the home screen, it seems like the JavaScript thread is suspended immediately, and listeners for the event are only called when Mobile Safari is re-enabled. pageshow
pagehide
pagehide
This is how you will listen to events:
window.addEventListener('pageshow', myPageShowListenerFunc, false);
window.addEventListener('pagehide', myPageHideListenerFunc, false);
source to share
For later versions of iOS pageshow
and pagehide
no longer work. However, you can now use an event visibilitychange
that fires when the user opens another browser tab, or when the browser is minimized (by pressing the home button).
So your code will look like
window.addEventListener('visibilitychange', myVisibilityHandleFunc, false);
or with jQuery
$(document).on('visibilitychange', myVisibilityHandleFunc);
From MDN :
The Page Visibility API lets you know when a web page is visible or in focus. In tabbed browsing, there is the possibility that any given web page will be in the background and therefore not visible to the user. When a user minimizes a web page or navigates to another tab, the API dispatches a visibilitychange event relative to the page's visibility.
There is a property document.webkitHidden
that can be used for iPhone to find out if a change was visible -> hidden or hidden -> visible.
source to share