Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在更改父窗口时阻止IE在IFrame中显示URL_Javascript_Internet Explorer_Iframe - Fatal编程技术网

Javascript 如何在更改父窗口时阻止IE在IFrame中显示URL

Javascript 如何在更改父窗口时阻止IE在IFrame中显示URL,javascript,internet-explorer,iframe,Javascript,Internet Explorer,Iframe,在IFrame中使用javascript:parent.location.href更改父窗口时,即短暂更改IFrame内容以列出父窗口更改到的url。Firefox、chrome和opera只需更改父窗口 有没有一种方法可以让IE跳过在IFrame中显示url而只更改父项 [编辑] 下面是复制它的示例代码 Iframe页面: <iframe id="finder" name="finder" src="content.html" scrolling="no" height="620" wi

在IFrame中使用javascript:parent.location.href更改父窗口时,即短暂更改IFrame内容以列出父窗口更改到的url。Firefox、chrome和opera只需更改父窗口

有没有一种方法可以让IE跳过在IFrame中显示url而只更改父项

[编辑]

下面是复制它的示例代码

Iframe页面:

<iframe id="finder" name="finder" src="content.html" scrolling="no" height="620" width="620" style="border:1px #c0c0c0 solid;"></iframe>

内容页:

<a href='javascript:parent.location.href="http://www.google.com"'>test link</a>

发生这种情况是因为您正在计算表达式,而不是调用方法

parent.location.href = "http://www.google.com";
如果我们将其移动到显式函数,我们将不再看到该行为:

<a href="javascript:void(parent.location.href = 'http://www.google.com')">test link</a>

但当然,没有理由在这种特定情况下使用JS:

<a href="http://www.google.com/" target="_parent">test link</a>

如果有,我们仍然应该优雅地降级:

<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>

var links=document.getElementsByTagName('a');

对于(var i=0;i,如果将javascript更改为以下内容,则可以将其保留为内联:

<a href='javascript:void(parent.location.href="http://www.google.com")'>test link</a>


通常,“set”表达式还返回表达式的右侧。IE获取表达式的返回值并显示它。通过放置“void()”在它周围,您可以删除返回值,这样IE就不会显示它。

IE7似乎不会这样做。您可以发布一些代码吗?它到底在哪里显示URL?IFrame的内容将被替换为显示父级最终更改为的URL的文本。这最准确地描述了问题 — “javascript:任何非空的内容”将结果显示为字符串。Rex的建议和target属性是实际可行的方法。顶部提示:永远不要使用javascript:URL做任何事情。+1这应该是正确的答案,Rex M的解决方案并不表明他们理解真正的问题。但是,如果你要使用javascript,没有理由这样做使用javascript:在href属性中,只需设置其onclick处理程序,更好的是,以非侵入方式进行。