Firefox中的open()和window.open()有什么区别? [英] What is the difference between open() and window.open() in Firefox?

查看:397
本文介绍了Firefox中的open()和window.open()有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在回答我的问题Pumbaa80发现调用 open() window.open(),请尝试下面的示例在Firefox中(在11.0测试):


  1. http://jsfiddle.net/9kqp5/ (调用打开; 在FF中的新选项卡中打开,前提是打开在新选项卡中打开新窗口设置,它是默认的)

  2. http: //jsfiddle.net/HLbLu/(调用 window.open ; 在新窗口中打开

    li>

但为什么地球上有差别?如果我尝试下面的例子

 <脚本> 
var a = 2;
函数hello(){alert(this.a); }

hello();
window.hello();
< / script>

调用函数 hello 同样,包括有相同的这个 !!!

解决方案

One你的小提琴调用 window.open 而另一个调用 document.open ,因为内联属性事件处理程序很奇怪。所以你最终在 http: //www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#dom-document-open



,因为你传递了3个参数,所以应该调用 window.open 。行为上的差异似乎是Firefox中的一个错误。我提交了 https://bugzilla.mozilla.org/show_bug.cgi?id=741266就这个。


In answering my question Pumbaa80 found a difference between calling open() and window.open(), try the following examples in Firefox (tested on 11.0):

  1. http://jsfiddle.net/9kqp5/ (calls open; opens in new tab in FF, provided that the "Open new windows in new tab instead" setting is on, which it is by default)

  2. http://jsfiddle.net/HLbLu/ (calls window.open; opens in new small window)

But why on earth there is a difference? If I try the following example:

<script>
var a = 2;
function hello() { alert(this.a); }

hello();
window.hello();
</script>

Both variants of calling function hello work exactly the same, including having the same this!!!

解决方案

One of your fiddles is calling window.open while the other is calling document.open, because the scope chain in inline attribute event handlers is weird. So you end up at http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#dom-document-open

That said, since you pass 3 arguments, this should be invoking window.open. The difference in behavior seems to be a bug in Firefox. I filed https://bugzilla.mozilla.org/show_bug.cgi?id=741266 on that.

这篇关于Firefox中的open()和window.open()有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆