0

I want to detect if user change the tab so the ajax requests stop. I tried with $(window).focus(function() { but it doesn't seems to work proper in my case. The problem is everything is stoped until you change the tab and return back to your site. And then even if you change the tabs again the requests don't pause. Any idea?

blako
  • 33
  • 6

1 Answers1

1

You need to use blur event:

$(window).on("blur", function() {
   // do whatever you want
});
letiagoalves
  • 11,224
  • 4
  • 40
  • 66
  • `Uncaught TypeError: Object [object Object] has no method 'on' ` – blako Sep 12 '13 at 10:56
  • when I change `on` with `bind` it works but why is it doubled? i think that cause the problem with ajax requests to not pause them. – blako Sep 12 '13 at 11:07
  • Check your jQuery version if it supports `on` function. it is not doubled. It appears to be doubled because you are seeing an `iframe`. See this: http://jsfiddle.net/uX84X/show/ (its the same code) – letiagoalves Sep 12 '13 at 12:41