【发布时间】:2016-06-16 04:01:58
【问题描述】:
我现在正在使用 frameset 和 frame,我对如何更改框架 URL 感到很困惑。我的客户他们使用 location 或 src 来设置/更改框架 URL。有时 location 工作,有时 src 工作,所以我要找出发生了什么。
我创建了 3 个 html 文件:parent.html、left.html、right.html。这是 parent.html 内容
<frameset cols="*,*">
<frame id="left" src="left.html">
<frame id="right" src="right.html">
</frameset>
这是left.html内容
<head>
<script>
function LocationThis() {
window.frames['innerleft'].location = "http://prntscr.com";
}
function SrcThis() {
window.frames['innerleft'].src = "http://prntscr.com";
}
function LocationOther() {
window.parent.frames['right'].location = "http://prntscr.com";
}
function SrcOther() {
window.parent.frames['right'].src = "http://prntscr.com";
}
</script>
</head>
<body>
<h1>Left</h1>
<button type="button" onclick="LocationThis();">Location this</button>
<button type="button" onclick="SrcThis();">Src this</button>
<button type="button" onclick="LocationOther();">Location other</button>
<button type="button" onclick="SrcOther();">Src other</button>
<hr/>
<iframe id="innerleft" src="" />
</body>
只有 src 在这种情况下有效。那么为什么 location 有时会起作用,而 src 不会呢?好的,现在我像这样更改脚本
//window.parent.frames['right'].location = "http://prntscr.com";
window.parent.frames[1].location = "http://prntscr.com";
然后 位置 工作正常。所以 frames['right'].src 和 frames[1].location 然后。但并非所有情况,有时 frames['right'].location 也可以。当我删除 id 并仅使用框架名称时,我必须使用 location
<frame name="right" src="right.html">
就是这样。哦,感谢 IE 拒绝接受 src,所以我必须像这样检查
try {
window.parent.frames["id"].src = {url};
}
catch(er) {
window.parent.frames["id"].location = {url};
}
对于这整个事情有一个巧妙的解决方案吗?
【问题讨论】:
-
这个项目就像 10 年前一样。我正在处理 IE 5,框架集......无法说服他们改变
标签: javascript html frame frameset