Javascript window、window.top 和 window.parent 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3473946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between window, window.top and window.parent?
提问by alter
I just noticed that top, windowand parentvariables are giving me the same value. I was testing this at gmail inbox page. Does anybody know what is the difference between these three values?
我只是注意到top,window和parent变量给了我相同的值。我正在 gmail 收件箱页面测试这个。有人知道这三个值有什么区别吗?
回答by thomasrutter
If you are within a frame:
如果您在一个框架内:
windowrefers to the current frame.parentrefers to the parent of the current frame.toprefers to the outermost frame.
window指的是当前帧。parent指的是当前帧的父级。top指最外框。
If you're not within any frame, these will all just be a reference to the current window. If you're only within one level of frame, parentand topwill both be a reference to the same thing.
如果您不在任何框架内,这些都只是对当前 window的引用。如果您只在一个框架内,parent并且top两者都是对同一事物的引用。

