admin管理员组文章数量:1325505
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
3 Answers
Reset to default 5From 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
版权声明:本文标题:jquery - How to stop javascript ajax requests in inactive Iframe? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742197784a2431399.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论