admin管理员组

文章数量:1325321

I have made Website, where various other pages are built-in as "apps" with i frames:

<iframe id="frame1" src="./app1.php">
<iframe id="frame2" src="./app2.php">

In these apps, there is javascript code executed, among others very high-frequent HTTP-Requests.

$('#app1button').click(function () {
     //Here i have to stop the HTTP-Requests which where fired from the JS of App2
     hideAllApps();
     showApp(app1);
});

app1 is polling information from a server very high frequently:

app1.php has Javascript in it::

 Handler = window.setInterval(getStatus, 100); //start status messages

When i now click on app2, the other app pops up, and i want to stop the javascript, which was loaded in app1.php, due to performance reasons.

$('#app2button').click(function () {
    //Here i have to stop the HTTP-Requests which where fired from the JS of App1
    hideAllApps();
    showApp(app2);
});

How can i do that? Do you have any ideas?

Thanks in advance.

I have made Website, where various other pages are built-in as "apps" with i frames:

<iframe id="frame1" src="./app1.php">
<iframe id="frame2" src="./app2.php">

In these apps, there is javascript code executed, among others very high-frequent HTTP-Requests.

$('#app1button').click(function () {
     //Here i have to stop the HTTP-Requests which where fired from the JS of App2
     hideAllApps();
     showApp(app1);
});

app1 is polling information from a server very high frequently:

app1.php has Javascript in it::

 Handler = window.setInterval(getStatus, 100); //start status messages

When i now click on app2, the other app pops up, and i want to stop the javascript, which was loaded in app1.php, due to performance reasons.

$('#app2button').click(function () {
    //Here i have to stop the HTTP-Requests which where fired from the JS of App1
    hideAllApps();
    showApp(app2);
});

How can i do that? Do you have any ideas?

Thanks in advance.

Share Improve this question edited Oct 2, 2012 at 14:35 mcknight asked Oct 2, 2012 at 14:30 mcknightmcknight 6151 gold badge6 silver badges18 bronze badges 3
  • Is it that you want to close all concuring ajax calls or just stop sending them? Because a simple clearInterval would work for the later. – Salketer Commented Oct 2, 2012 at 14:33
  • But with a simple "clearinterval" in my main page i can't address javascript that was loaded in an iframe - or am i wrong? – mcknight Commented Oct 2, 2012 at 14:34
  • You are right, unless you affect it to "top" (your main window)... top.handler – Salketer Commented Oct 2, 2012 at 14:36
Add a ment  | 

3 Answers 3

Reset to default 5

From within frame2 you can try window.parent.frame["frame1"].stop() and in frame 1 you define stop() as a function which clears your interval.

Since all iframes have there own window.You can use window.onfocus. window.onblur. put code inside each iframe. jsfiddle

var Handler ;
window.onfocus = function(){
         Handler = window.setInterval(getStatus, 100); //start status messages

}
window.onblur = function(){

  clearInterval(Handler );
}

make sure both iframes are are hidden on the page load

once you open them with

$('#app2button').click(function () { 

add javascript code to load the content with

$('#app2button').html().load()

本文标签: jqueryHow to stop javascript ajax requests in inactive IframeStack Overflow