I have a series of pages that open popups (new tabs in Mobile Safari.) Each of these popups needs to know when they are the focused or not. On desktops, we use window.
I don't think that onblur can be detected, but this is a code to detect onfocus:
var timestamp=new Date().getTime();
function checkResume()
{
var current=new Date().getTime();
if(current-timestamp>5000)
{
var event=document.createEvent("Events");
event.initEvent("focus",true,true);
document.dispatchEvent(event);
}
timestamp=current;
}
window.setInterval(checkResume,50);
Then you just write:
document.addEventListener("focus",function()
{
alert("Focus detected");
},false);