Mik*_*ike 2 javascript iframe internet-explorer
在IFrame中使用javascript:parent.location.href更改父窗口时,IE会短暂更改IFrame内容以列出父级正在更改的URL.Firefox,chrome和opera只是更改父窗口.
有没有办法让IE跳过显示IFrame中的网址,只是更改父级?
[编辑]
这是复制它的示例代码.
iframe页面:
<iframe id="finder" name="finder" src="content.html" scrolling="no" height="620" width="620" style="border:1px #c0c0c0 solid;"></iframe>
Run Code Online (Sandbox Code Playgroud)
内容页:
<a href='javascript:parent.location.href="http://www.google.com"'>test link</a>
Run Code Online (Sandbox Code Playgroud)
发生这种情况是因为您正在评估表达式,而不是调用方法.
parent.location.href = "http://www.google.com";
Run Code Online (Sandbox Code Playgroud)
如果我们将其移动到显式函数,我们将不再看到该行为:
<a href="javascript:void(parent.location.href = 'http://www.google.com')">test link</a>
Run Code Online (Sandbox Code Playgroud)
但是,当然,没有理由在这个特定情况下使用JS:
<a href="http://www.google.com/" target="_parent">test link</a>
Run Code Online (Sandbox Code Playgroud)
如果有的话,我们仍然应该优雅地降级:
<a href="http://www.google.com/" target="_parent">test link</a>
<script type="text/javascript">
var links = document.getElementsByTagName('a');
for(var i=0;i<links.length;i++) {
if(links[i].target == '_parent') {
links[i].onclick = handleParentClick;
}
}
function handleParentClick(e) {
var sender = e ? (e.target || e) : window.event.srcElement;
parent.location.href = sender.href;
return false;
}
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2243 次 |
| 最近记录: |