I have a script which called a JS function every 2.5 seconds. This is the code that I use,
<script type='text/javascript'>
    getMsgs();
    setInterval(function() {
      getMsgs();
    }, 2500);
</script>
This code keeps on executing even if I am on an other tab on the browser. How can I make this only execute when the tab with that specific page is open?
 
     
    