Skip to content

Instantly share code, notes, and snippets.

@to
Created June 7, 2012 03:56
Show Gist options
  • Save to/2886473 to your computer and use it in GitHub Desktop.
Save to/2886473 to your computer and use it in GitHub Desktop.
Fake Pageshow Event for iOS Home App
var time = Date.now();
setInterval(function(){
var now = Date.now();
if(now - time > 5000)
alert('pageshow(fake)');
time = now;
}, 1000);
@to
Copy link
Author

to commented Jun 7, 2012

iOS 5のSafariにはwebkitvisibilitychange/visibilitychangeが存在せず、ウィンドウのfocus/blurも動作しない。
pageshow/pagehideはあるが、ホームに置いたアプリではロック復帰後にイベントが発生しない。
これを回避するため、タイマのズレからバックグラウンドを判定しpageshowの代わりとした。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment