Jump to content

iOS detecting when the user minimizes the browser


Rolf
 Share

Recommended Posts

Hi, 

 

Currently I'm working on a game that uses music loops.  I need to pause the music when the user opens a new tab or minimizes the browser. 

 

I use this code: 

var eventName = 'visibilitychange';if ( document.webkitHidden != undefined ){	eventName = 'webkitvisibilitychange';}function handleVisibilityChange() {	if (document.webkitHidden||document.hidden) {		currentLoop.pause();	} else {		currentLoop.play();	}}document.addEventListener(eventName, handleVisibilityChange, false);

On Android works very well, but on iOS only works when the user opens a new tab or navigates to another tab, not when the user minimizes the browser or switches to another app. window.blur nor window.focus work either. 

 

Any workaround?

 

Thank you!

 

 

Link to comment
Share on other sites

  • 2 months later...

Hi,

try using

window.addEventListener("pagehide", function() {    currentLoop.pause();});window.addEventListener("pageshow", function() {    currentLoop.play();});

it handles browser hide and show, but doesn't handle tab switching.

The answer is based on safari documentation https://developer.apple.com/library/ios/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...