2017-04-20 63 views
0

當我的iFrame刷新時,在我的iframe中使用的javascript文件(app.js)沒有得到執行嗎?當iFrame刷新時,iFrame中的Javascript文件不會被執行

基本上就是現在發生的事情是: 當我第一次加載的index.html,javascript的app.js輸出的「Hello World」到控制檯,但隨後一度的iframe就會自動刷新(通過reloader。 js)一切刷新,但JavaScript,我的意思是,一旦iframe被刷新,我不會得到一個新的「你好世界」。

有沒有人通過相同的問題?

的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

+0

你可以顯示'reloader.js'的代碼嗎? – shaochuancs

回答

1

試圖通過這種重裝,

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

這樣做!雖然我有點困惑,爲什麼設置幀的src不起作用... –

0

我認爲這個問題是你必須保持你的reloader.js中的index.html這將刷新當前頁面(index.html的)只,而不是iframe.html。因此,簡而言之,iframe.html不會在每次重新加載index.html時重新加載。