Do you guys have any idea how to detect mobile Chrome sleep event? I tried with:
window.onblur = fnPause;
document.onfocusout = fnPause;
document.body.onfocusout = fnPause;
var hidden, visibilityChange;
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support
hidden = "hidden";
visibilityChange = "visibilitychange";
} else if (typeof document.mozHidden !== "undefined") {
hidden = "mozHidden";
visibilityChange = "mozvisibilitychange";
} else if (typeof document.msHidden !== "undefined") {
hidden = "msHidden";
visibilityChange = "msvisibilitychange";
} else if (typeof document.webkitHidden !== "undefined") {
hidden = "webkitHidden";
visibilityChange = "webkitvisibilitychange";
}
if (typeof document.addEventListener === "undefined" ||
typeof document[hidden] === "undefined") {
// doesn't support event listeners :(
} else {
// Handle page visibility change
document.addEventListener(visibilityChange, function() {if (document[hidden]) {fnPause();} else {fnResume();}}, false);
}
Still fnPause() is never called when I leave the html5 game open and phone goes sleep mode and locks.
This question is not a duplicate of - Is it possible, in JavaScript, to detect when the screen is turned off in the Android & iOS browsers . Two of the solutions I tried above (blur and pagevisibility) without success and the third - using timers - only detects resume event and not sleep.