Chrome document.title issue

Posted: Tuesday, June 12, 2012 by Venkat Pola in Labels:
0

We generally rotate the page title for the sake of notifications and once the user gains focus of the concerned tab we reset the page title to old one.

This works out mostly in all browsers but in chrome there is a small problem.

Focus gain / lost of chrome browser works fine but there is a problem in focus gain / lost browser tab. In case of browser tab focus gain / lost, Chrome hides the whole browser tab DOM as the tab is not visible to the user and redraws whole DOM as soon as the tab gains focus. I would say this is really a great performance technique.

But the problem comes here only, as the document.title is part of DOM and it is redrawing what ever we set from Javascript in the onfocus listener gets overrides.

As a hack of this we could reset the title in asynch manner something like below,

window.onfocus = function(){

setTimeOut(function(){
document.title = your_title
},200) ;

}
Note : - If you still face the problem even with this approach also, then better increase the title rotation speed to 1-2 sec.
Enhanced by Zemanta

0 comments: