How do I get the Window object from the Document object?

前端 未结 6 1677
太阳男子
太阳男子 2021-01-01 08:29

I can get window.document but how can I get document.window? I need to know how to do this in all browsers.

6条回答
  •  情话喂你
    2021-01-01 09:06

    The Window object is the top level object in the JavaScript hierarchy, so just refer to it as window

    Edit: Original answer before Promote JS effort. JavaScript technologies overview on Mozilla Developer Network says:

    In a browser environment, this global object is the window object.

    Edit 2: After reading the author's comment to his question (and getting downvotes), this seems to be related to the iframe's document window. Take a look at window.parent and window.top and maybe compare them to infer your document window.

    if (window.parent != window.top) {
      // we're deeper than one down
    }
    

提交回复
热议问题