簡體   English   中英

首次更改后,JavaScript未更改iframe源

[英]Javascript not changing iframe source after first change

我有一個腳本,其中包含帶有foo.php的Iframe。

我的頁面上還有5個鏈接,當單擊這些鏈接時會觸發javascript函數來更改源。 唯一的問題是,當我單擊一個鏈接並更改了iframe后,下次單擊鏈接時,它不再更改。

這是JavaScript:

<script>
function changeSource(newSource) {
    parent.sec1.document.location=newSource;
}
</script>

這是HTML:

<a href="#calandar" onclick="changeSource('http://www.example.com/view.php')">Calandar</a><br />
<a href="#facebook" onclick="changeSource('http://www.facebook.com')">Facebook</a><br />
<a href="#gmail" onclick="changeSource('http://www.gmail.com')">Gmail</a><br />
<a href="#reddit" onclick="changeSource('http://www.reddit.com')">Reddit</a><br />
<a href="#twitter" onclick="changeSource('http://www.twitter.com')">Twitter</a><br />
</div>

<div id="sec1">
<iframe src="view.php" name="meat" width="100%" height="75%" ></iframe>
</div>

謝謝。

如果我正確理解了您的問題,請嘗試向該iframe添加ID,然后執行以下操作:


function changeSource(newSource) {
  document.getElementById('yourIframeId').src = newSource;
}

希望能幫助到你

<script>
function changeSource(newSource) {
    document.getElementById('my-iframe').src=newSource;
}
</script>
...
...
...
<iframe src="view.php" id='my-iframe' width="100%" height="75%" ></iframe>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM