当我的 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/