Javascript window.top.location 与 window.location

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5354561/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 16:49:19  来源:igfitidea点击:

window.top.location vs window.location

javascriptfacebookiframewindow.location

提问by asdf_enel_hak

how to sync window.top.location and window.location?

如何同步 window.top.location 和 window.location?

采纳答案by Josh Stodola

This is how you set the parent of the frame (top) to the location of the frame document...

这就是将框架 ( top)的父级设置为框架文档位置的方式...

top.location = self.location;

Of course, this code must be executed within the iframe, and is succeptible to the Same-Origin Policy.

当然,此代码必须在 iframe 内执行,并且可以接受同源策略

回答by Anant Dabhi

window.top.location is return you to broswer's address bar location even you'r in i-frame or page.. window.location is return location of your current page address in case facebook apps. if you want to top query-string you have to use

即使您在 i-frame 或页面中,window.top.location 也会将您返回到浏览器的地址栏位置。 window.location 是您当前页面地址的返回位置,以防 facebook 应用程序。如果你想顶部查询字符串,你必须使用

alert(window.top.location);

alert(window.top.location);

if u want to replace top location then

如果你想替换顶部位置,那么

window.top.location = "http://whatever.com";

window.top.location = "http://whatever.com";