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()">
精彩评论