When the page is loaded the focus/blur state isn't activated. When switching to for example another tab blur
show, and upon switching back to the page focus
activates – but at first load of the page none of the states are activated, why? Is this expected behavior or have I messed something up?
$(function(){
$(window).focus(function() {
document.title="focus";
});
$(window).blur(function() {
document.title="blur";
});
});
Update
Seems like Adding }).focus();
as suggested by Rory in the comments doesn't make any difference anymore due to changes in browsers – so I'm still looking for a way to detect focus on page load.
Update 2 I've added an onload to act as a "pretend focus", so far this is the best I've managed to come up with. Don't know if this a reasonable solution, so if you've got a better one I'd love to take part of it.
window.onload = function(){
document.title="focus";
};
window.onblur = function() {
document.title="blur";
};
window.onfocus = function() {
document.title="focus";
};