views:

57

answers:

2

I remember having used such an event, but I can't remember the name.

The specific task I'm trying to accomplish is to stop my slideshow when the browser window isn't in the foreground. I'm fading the different images with jQuery, which uses quite some CPU power.

Is there an event that tells me, when the user switches to another application / page.

+2  A: 

You should be able to use the onblur event of the window to detect that change.

Jordan
+2  A: 

There were some bugs with window focus event so I used mousemove event too.

$(window).blur(function(){
  // stop the slideshow
}).bind("focus mousemove", function(){
  // start the slideshow
});
Anpher
Seems not to be a standard: https://developer.mozilla.org/en/DOM/window.onblur (Still it's good enough for me, it's just a nice functionality to have.)
Georg
Could you elaborate on what "bugs" there are?
musicfreak
Focus event wasn't fired at some unknown cases. Sometimes were and sometimes weren't fired. I don't why is it so. Maybe ask Horatio??
Anpher
@Georg: that's because of `[window|element].onblur`, as well as all other DOM level 0 event handlers, are not part of any standard (all right, they probably will be part of [HTML 5](http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#event-handlers-on-elements,-document-objects,-and-window-objects)).
Marcel Korpel