Search code examples
javascriptonblur

Javascript window.blur()


I have this piece of code:

window.addEventListener( "focus" , function(){
    window.console.log("focus");
} , false );

window.addEventListener( "blur" , function(){
    window.console.log("blur");
} , false );

And if I run : setTimeout("window.focus();",2000); from firebug's console I get "focus" after 2 seconds but if I run setTimeout("window.blur();",2000); I don't get "blur".

Could someone help me please? I don't understand it, it should work.


Solution

  • I'm not quite sure, but try this:

    setTimeout(function() {
        window.blur();
    }, 2000);