iFrame 刷新时,iFrame 内的 Javascript 文件不会被执行

标签 javascript html iframe

当我的 iFrame 刷新时,我的 iframe 中使用的 javascript 文件 ( app.js ) 没有被执行,有什么原因吗?

基本上现在发生的事情是: 当我第一次加载 index.html 时,javascript app.js 向控制台输出“hello world”,但是一旦 iframe 自动刷新(通过 reloader .js )除了 javascript 之外,所有内容都会刷新,我的意思是,一旦刷新 iframe,我就不会得到新的“hello world”。

有人遇到过同样的问题吗?

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>treedux - Development Server</title>
    <script src="reloader.js"></script>

    <script>

    </script>
  </head>
  <body>
    <div class="topbar">
      <div class="icon-menu"></div>
        3dux.io Header
    </div>
    <iframe id="treeduxwrapper" class="iframe" src="iframe.html"></iframe>
  </body>
</html>

iframe.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>treedux - Development Server</title>
    <script type="text/javascript" src="app.js"></script>
  </head>
  <body>
    <div class="topbar">
      <div class="icon-menu"></div>
        CONTENT
    </div>

  </body>
</html>

app.js

console.log('hello world')

提前致谢, TF

最佳答案

尝试通过此重新加载,

document.getElementById('treeduxwrapper').contentWindow.location.href = "iframe.html"

关于iFrame 刷新时,iFrame 内的 Javascript 文件不会被执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43510591/

相关文章:

javascript - Jquery无法获取&lt;iframe&gt;元素的内容

javascript - 从 JSON API 获取数据并以 HTML 形式显示

html - 需要最后一个 div 全宽

javascript - 单击时确定句子的字符

jquery - 如何删除没有 ID/Class 但基于其 scr 的 iframe

javascript - 使用 Jquery 将 iframe 调整为内容

javascript - Google 分析与 Chartbeat 分析

javascript - 重复函数导致模态标题

javascript - 如何将 Prop 传递给第三方组件?

javascript - AngularJs:单独的 js 文件中的嵌套指令