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

标签 javascript google-chrome

我只是偶然忘记在我的实验中删除 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/

相关文章:

javascript - 使用javascript显示部分JSON数据

google-chrome - Firefox 到 Chrome 和 Chrome 到 Firefox 的 WebRTC 视频聊天无法正常工作

css - Firefox 和 Chrome 的 margin 值

css - Chrome 浏览器上奇怪的对 Angular 线

javascript - 通过 iframe 模拟手机屏幕尺寸

javascript - 渲染 react-bootstrap 组件时出错

javascript - pageshow后刷新jquery mobile中的页面

javascript - 使 facebook 登录与 Android Webview 一起工作

javascript - 我可以创建一个不打开滚动条的元素吗?

css - Chrome CSS 绝对位置故障