gpt4 book ai didi

javascript - 文档不会加载到 iframe 中,但名称已更改但正确

转载 作者:行者123 更新时间:2023-11-28 00:11:29 25 4
gpt4 key购买 nike

我想要实现的是能够通过 java 更改其名称,将 href 的内容加载到三个 iframe 之一。

问题是:Chrome 总是将内容加载到第一个 iframe 中,忽略其名称更改,在 Firefox 中不会出现此问题。

function change_name()
{
document.getElementById('frame1').name = "#" ;
document.getElementById('frame2').name = "main_frame" ;
};
.frame {
width:100px;
height:100px;
}
<iframe id="frame1" name="main_frame" class="frame"></iframe>
<iframe id="frame2" name="#" class="frame"></iframe>
<iframe id="frame3" name="#" class="frame"></iframe>

<input type="submit" onclick="change_name()" value="change iframe name"/>
<a href="www.stackoverflow.com" target="main_frame">load page into iframe</a>

jsfiddle 演示了我正在尝试做的事情:http://jsfiddle.net/514y7v4m/1/
非常感谢任何帮助

最佳答案

偶然发现这个链接:http://help.dottoro.com/ljbimuon.php

对脚本进行一些修改后,我相信这可能是解决方案。更改 contenWindow.name 而不是单独的名称似乎可以解决问题。

function change_name() {
var one = document.getElementById('frame1');
one.contentWindow.name = "#";
console.log("The name is: " + one.name);
console.log("The name of the window: " + one.contentWindow.name);

var two = document.getElementById('frame2');
two.contentWindow.name = "main_frame";
console.log("The name is: " + two.name);
console.log("The name of the window: " + two.contentWindow.name);
};

关于javascript - 文档不会加载到 iframe 中,但名称已更改但正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30843699/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com