gpt4 book ai didi

javascript - Chrome中指向Window对象的 `parent`变量在哪里定义的?

转载 作者:行者123 更新时间:2023-11-30 20:05:58 25 4
gpt4 key购买 nike

我只是偶然忘记在我的实验中删除 console.log(parent) 并且它记录了 Window。我不知道有全局变量 parent。它在哪里定义?我使用的是最新的 Chrome。

最佳答案

它在 the HTML specification 中定义, 具体来说 here :

The parent IDL attribute, on getting, must run the following algorithm:

  1. Let windowProxy be this Window object's WindowProxy object.

  2. If there is no browsing context with windowProxy as its WindowProxy object, then return null.

  3. Let context be that browsing context.

  4. If context is a child browsing context of another browsing context parent, then return parent's WindowProxy object.

  5. Otherwise, context must be a top-level browsing context. Return context's WindowProxy object.

另见 MDN .

基本上,parent 是窗口的父级(例如,它是一个框架或 iframe),如果它有的话,或者如果没有,则为窗口本身。

还有相关但不同的 opener ( MDN | spec )。

关于javascript - Chrome中指向Window对象的 `parent`变量在哪里定义的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52935127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com