0

I'm developing a dynamic web page with nested pages. Inner pages have their own script to be live and modular.

The problem comes when i want to remove one of the inner pages. Infact the HTML code is removed but the inner script keeps running.

Is it possible to stop the script?

This is a brief view of my solution:

Note that in this sample the ID are all the same but in the real solution they are identified by unique ID using php GET["ID"] value.

outerPage.php

<HEAD>
    <script>
    var fRunUpdate = true;
        $(document).ready(function() {

           $("#inner1").load("inner.php");
           $("#inner2").load("inner.php");
           $("#inner3").load("inner.php");

        }
    </script>
</HEAD>
<BODY>
    <div id="inner1"></div>
    <div id="inner2"></div>
    <div id="inner3"></div>
</BODY>

innerPage.php

<HEAD>
    <script>
    var fRunUpdate = true;
        $(document).ready(function() {
           function update(){
               //do something
               $("#contentToUpdate").html("content");
               setTimeout(update,1000);
           }
        }
    </script>
</HEAD>
<BODY>
    <div id="contentToUpdate"></div>
</BODY>
snovelli
  • 5,804
  • 2
  • 37
  • 50

1 Answers1

1

You will have to use stoptimeout or clear interval I just read out this link and get it

How to stop a setTimeout loop?

Take function in variable

foo = setTimeout(function, time);

and then just clear it out

clearTimeout(foo);

I hope this will help you

Community
  • 1
  • 1
Just code
  • 13,553
  • 10
  • 51
  • 93