3

我在 IE8 中遇到了一个非常奇怪的行为。

我有一个简单的 javascript 函数来创建一个弹出窗口。弹出窗口创建正常,但父窗口转发到一个完全空白的窗口,该窗口只打印 [object]。我必须点击后退按钮才能返回原始页面。

<a href='javascript:window.open("http://endic.naver.com/search.nhn?query=In&searchOption=entry_idiom","Dictionary","width=500, height=500")' target="_blank">Click me</a>

Chrome没有问题,只有IE。我怎样才能摆脱这种烦人的行为?

4

3 回答 3

11

window.open问题是 Internet Explorer 按预期执行代码,但还在新文档中显示返回值。由于window.open返回对新文档的对象引用,因此它将转换为字符串 - [object Object]- 并显示。

要解决此问题,您可以添加return false以防止浏览器返回任何内容。

<a href='javascript:window.open("http://endic.naver.com/search.nhn?query=In&searchOption=entry_idiom","Dictionary","width=500, height=500"); return false' target="_blank">Click me</a>

编辑- 请参阅此答案下方的 OP 评论。解决方案是将 JavaScript 移动到onclick属性,并将target属性更改为与弹出窗口名称相同。

<a href="javascript:void(0);" onclick='window.open("http://endic.naver.com/search.nhn?query=In&searchOption=entry_idiom","Dictionary","width=500, height=500");' target="Dictionary">Click me</a>
于 2013-03-17T16:01:27.137 回答
2

试试这个:http: //jsfiddle.net/kelervin/Pf8Rw/

HTML

    <a href="http://www.google.com" class="open-popup">test</a>

查询

    $('.open-popup').click(function(e) {
        e.preventDefault();
        window.open(this.href, '_blank', 'width=300,height=200');
    });

注意:在 chrome 和 IE 8 中测试

于 2013-03-17T15:56:24.600 回答
0

您需要禁用跟踪出站链接。将以下 javascript 代码添加到 index.html 文件中:

<script type="text/javascript"> var clicky_custom = clicky_custom || {}; clicky_custom.outbound_disable = 1; </script>

于 2015-01-28T19:08:43.397 回答