如何构建一个能够监控页面何时获得焦点的网页,尤其是当Safari处于后台并且用户将Safari切换回前台时.
在iPhone上切换到Safari时,下面的代码不会触发事件
<html>
<head>
<script type="text/javascript">
window.onfocus = function() { alert("onfocus"); };
</script>
</head>
<body>
Main text
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
根据http://www.quirksmode.org/dom/events/index.html:Windows iPhone在窗口获得焦点时不会触发事件.
所以我的问题仍然是:如何通过在Safari for iPhone中的网页上使用javascript来检测窗口是否获得焦点?