开发者

Javascript event when changing/focusing tab/window

Is there an event handler for focusing or blurring a tab or window in jQu开发者_运维知识库ery? blur() and focus() don't seem to work on window.


You can bind the window's blur function, so jQuery would be $(window).blur(handler)

You can even test it on this page real quick, pop javascript: window.onblur = function() { alert("Blur"); }; into your action bar and alt tab.


http://jsfiddle.net/6ckFZ/

jQuery blur event on window works for me.

$(window).blur(function() {
  alert('Handler for .blur() called.');
});


You could use onkeydown if people will be typing into a box, or onfocus for the initial click into the window. See the examples below.

<input type="text" onfocus="myFunction()">

or

<input type="text" onkeydown="myFunction()">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜