【问题标题】:How can i revoke a setTimeout variable from an iframe (Javascript)?如何从 iframe (Javascript) 中撤销 setTimeout 变量?
【发布时间】:2013-07-24 09:11:08
【问题描述】:

我对 setTimeout 和 clearTimeout 有疑问: 在 index.php 中:

enter code here
dateVar  = new Date();
timer = setTimeout(function() {MyFuncFirst();}, 10000);
$(document).click(function(e)
                        {
                          clearTimeout(timer);
                          timer = setTimeout(function() {MyFuncNext();}, 10000);
                         });

比我想在 myframe.php 的 iframe 中使用 clearTimeout :

clearTimeout(parent.timer);

我不能 但是,同样的代码正在运行

parent.dateVar = new Date();

为什么会这样?我该如何解决?

【问题讨论】:

    标签: javascript jquery parent-child parent children


    【解决方案1】:

    您不能与 iFrame 中的变量进行交互。在 iFrame 中加载的页面是一个完全独立的页面。

    要克服这个问题,您可能需要研究 AJAX 在两个页面之间进行通信,就像您在两个网站之间进行的那样。

    【讨论】:

    • “您不能与 iFrame 中的变量进行交互。”你可以under certain conditions
    • @PleaseStand 好了。我不建议使用它,但很好找。
    【解决方案2】:

    每个Window 对象都有自己的“活动计时器列表”(请参阅​​the spec)。所以试试这个:

    parent.clearTimeout(parent.timer);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-28
      • 2021-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多