views:

124

answers:

1

Hello, I tried to search but could not find out anything useful. This is a piece of code for my Greasemonkey script. Basically, I want to have the same effect as Gmail. When the page loads and you have new messages, the title will change repeatedly and make you notice. The problem is it does not work for the first time.

For example: The user opens the page on new tab and do not move to the page, it does not work. But if the user moves to the page and then move to other tab, the script works.

Can anyone point me the righ direction?

function startBlink(){
    window.blinkInterval = setInterval(function(){
    if(document.title != "Message"){document.title = "Message";}
    else{document.title = "Application";}
   } , 1000);
}
function blink(){ 
    document.addEventListener("blur",function(){setTimeout(startBlink(),1000);},false);
    document.addEventListener("focus",function(){clearInterval(window.blinkInterval);},false);
}

window.addEventListener("load",blink,false);
A: 

have you thought about changing (iterating through multiple variants of) window title instead of blinking (blur/focus)? that also attracts an eye.

dusoft
Thanks for answering. If you read the code carefully, you can see that the script will change the title repeatedly when the window event is onblur.
hoangquan