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?
Asked
Active
Viewed 1,555 times
0

blako
- 33
- 6
-
1Please show all your code – Jez D Sep 12 '13 at 10:53
-
yes , use `blur` : http://jsfiddle.net/cherniv/XALfC/ – Ivan Chernykh Sep 12 '13 at 10:55
-
`The problem is everything is stoped until you change the tab and return back to your site.` thats what happens when using blur or focus – blako Sep 12 '13 at 10:59
-
possible duplicate of [How to tell if browser/tab is active](http://stackoverflow.com/questions/1760250/how-to-tell-if-browser-tab-is-active) – Boris Zagoruiko Sep 12 '13 at 11:19
1 Answers
1
You need to use blur
event:
$(window).on("blur", function() {
// do whatever you want
});

letiagoalves
- 11,224
- 4
- 40
- 66
-
-
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