What is the difference between open() and window.open() in Firefox?

前端 未结 6 2065
抹茶落季
抹茶落季 2021-01-18 10:16

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

6条回答
  •  花落未央
    2021-01-18 11:10

    Inside the event handler, open by itself will resolve to document.open. As Boris Zbarsky mentioned in a comment and in his answer, this is expected behavior, specified by HTML5. In the section on event handlers, step 6 specifies:

    6. Using the script execution environment created above, create a function object (as defined in ECMAScript edition 5 section 13.2 Creating Function Objects), with:

    (...)
    Lexical Environment Scope

    1. Let Scope be the result of NewObjectEnvironment(the element's Document, the global environment).
    2. If the element has a form owner, let Scope be the result of NewObjectEnvironment(the element's form owner, Scope).
    3. Let Scope be the result of NewObjectEnvironment(the element's object, Scope).
      (...)

    In other words, variable references within the event handler will be resolved in the order:

    1. local scope
    2. element properties
    3. owner form properties (if applicable)
    4. document properties
    5. global scope

提交回复
热议问题