0
(function($){

    $(window).focus(function(){
        document.title = 'focused';
    });

    $(window).blur(function(){
        document.title = 'not focused';
    });

})(jQuery);

What it's supposed to do: if a tab is focused, the title should be 'focused'; if it's not, then title should be 'not focused'.

What it's doing in reality: after leaving a tab unfocused, its title will remain forever 'not focused'.

This is working fine in Firefox, but not in Chrome, anyone got suggestions? Thanks!

user2567834
  • 41
  • 1
  • 5

2 Answers2

0

Check out this answer, you could easily modify that code to complete the task you've outlined here.

Community
  • 1
  • 1
matty-d
  • 2,623
  • 3
  • 18
  • 21
0

This is in fact a reported bug of Chrome and it is happening in version 29, when you change between tabs. It seems to be a race condition that will not update the title of the tab, despite the fact that document.title is correctly filled.

A possible workaround for the code above is to create a timer to change the title again. The following code works, but you can also just set the text inside the timer function.

(function($){

$(window).focus(function(){
    document.title = 'focused';
});

$(window).blur(function(){
    document.title = 'not focused';

    window.setTimeout(function () {
        var temp = document.title;
        document.title = temp + "_";
        document.title = temp;
    }, 200);
});

})(jQuery);
nakib
  • 4,304
  • 2
  • 28
  • 39