Just to have the right answer here:
$(function() {
$(window).focus(function() {
console.log('Focus');
});
$(window).blur(function() {
console.log('Blur');
});
});
Note that in FF and IE the “Focus” event fires on ~document load, while in Chrome it only fires if the window had lost focus before and now it has regained it.