javascript - jQuery mobile stop running the script in the current page used after moving to the next page -


in jquery mobile application, iam having scripts being loaded @ index page(say index.php) , not using (rel="external" or data-ajax="false")for linking pages keep appication loaded ajax. in application, want run script 1 page(say home.php) , after leaving page, want kill script being used.in home.php, using $(document).on('pageinit', function(){ }) loading script.

but found script iam using in home.php running throughout application after leaving page.

how stop script running used through page-init function without using (rel="external" or data-ajax="false")?

here code using in home.php,

<script type="text/javascript">                 $(document).on('pageinit', function(){     var auto_refresh = setinterval(              function ()             {                  /*  */                 $("#color-bar").load("controller/file.txt");                         }, 3000);                 }); </script> 

i want stop loading file.txt after leaving home.php.

as, omar suggested want give id instead of $(document). using pagebeforeshow or pageshow , pagehide , clearing interval solve issue. following code works me,

var auto_refresh; $("#light-page").on('pagebeforeshow', function(){   auto_refresh = setinterval(function () {     // code   }, 3000); });  $('#light-page').on('pagehide', function () {    clearinterval(auto_refresh); }); 

adding id in html:

<div data-role="page" id="light-page">    </div> 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -