nineteen
nineteen

Reputation: 33

Javascript event when changing/focusing tab/window

Is there an event handler for focusing or blurring a tab or window in jQuery? blur() and focus() don't seem to work on window.

Upvotes: 3

Views: 6005

Answers (3)

maudulus
maudulus

Reputation: 11035

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()">

Upvotes: 0

Eliasdx
Eliasdx

Reputation: 2180

http://jsfiddle.net/6ckFZ/

jQuery blur event on window works for me.

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

Upvotes: 6

Robert
Robert

Reputation: 21388

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.

Upvotes: 7

Related Questions