javascript window.open 在 IE 中打开两个弹出窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15462752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
window.open opens two popup windows in IE
提问by Matthew Oakley
I'm getting a really strange behaviour in IE8.
我在 IE8 中遇到了一个非常奇怪的行为。
I have a simple javascript function to create a popup window. The popup window is created ok, but the parent window forwards to a completely blank window that just prints [object]. I have to hit the back button to get back to the original page.
我有一个简单的 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>
There is no problem in Chrome, just IE. How can I get rid of this annoying behaviour?
Chrome没有问题,只有IE。我怎样才能摆脱这种烦人的行为?
回答by Liam Newmarch
The problem is Internet Explorer executes the code as expected, but also displays the return value of window.openin a new document. Since window.openreturns an object reference to the new document, this gets converted to a string - [object Object]- and is displayed.
问题是 Internet Explorer 按预期执行代码,但也在window.open新文档中显示 的返回值。由于window.open返回对新文档的对象引用,因此将其转换为字符串 - [object Object]- 并显示出来。
To remedy this, you can add return falseto prevent the browser returning anything.
为了解决这个问题,您可以添加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>
Edit- See OP's comment below this answer. The solution was to move the JavaScript to an onclickattribute, and to change the targetattribute to be the same as the popup name.
编辑- 请参阅此答案下方的 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>
回答by Yasser Shaikh
Try this : http://jsfiddle.net/kelervin/Pf8Rw/
试试这个:http: //jsfiddle.net/kelervin/Pf8Rw/
HTML
HTML
<a href="http://www.google.com" class="open-popup">test</a>
JQUERY
查询
$('.open-popup').click(function(e) {
e.preventDefault();
window.open(this.href, '_blank', 'width=300,height=200');
});
Note : Tested in chrome and IE 8
注意:在 chrome 和 IE 8 中测试
回答by Vishwani
You need to disable Track outbound links. Add the following javascript code to index.html file:
您需要禁用跟踪出站链接。将以下 javascript 代码添加到 index.html 文件:
<script type="text/javascript">
var clicky_custom = clicky_custom || {};
clicky_custom.outbound_disable = 1;
</script>
<script type="text/javascript">
var clicky_custom = clicky_custom || {};
clicky_custom.outbound_disable = 1;
</script>

