0

How to stop jquery function on tab change? Code of the Jquery js function is given below.

function move(){
addEventListener('load', function() {
createProgressbar('progressbar1', '40s', function() {
document.getElementById("close").style.display = "block";
 document.getElementById("msg").style.display = "none";
}); 
});
}

Anyone can help me in that? If required any other info comment please.

Harman Cheema
  • 152
  • 1
  • 3
  • 11

2 Answers2

1

Please see below to get a general idea.

playing = function() {
    foo = window.setInterval(function() {
        console.log('as')
    }, 500);
}

$(window).blur(function(e) {
   clearInterval(foo);//clear the interval..which inturn stop execution
});

$(window).focus(function(e) {
//will get executed when current tab is focused
 playing()
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Note: click on/outof the output area after running snippet to see it working.
Rohith K P
  • 3,233
  • 22
  • 28
0

If you are performing some action of loading (say) on one tab and during the process of loading, if you switch to another tab, And you need the previous process of the loading to be stopped, then it might not happen.

But you can do is hide all elements (displayed related to the loading) that you do not want to display as soon as you have changed the tab.

S Jayesh
  • 191
  • 1
  • 4
  • 19