选项卡式网站中的 window.location

发布于 2024-11-10 16:58:32 字数 334 浏览 7 评论 0原文

我正在处理一个使用选项卡的网站。外部选项卡是 facebook.com。内部选项卡是 Facebook 应用程序。

当我运行以下函数时:

 $(document).ready(function() {
    // to show it in an alert window
    alert(window.location);

    // to store it in a variable
    var loc = window.location;
});

返回的值是内部选项卡的 url,即主机。有没有办法使用 JQuery 函数生成外部选项卡的 url?

I'm dealing with a website that uses tabs. The outer tab, is facebook.com. The inner tab is a facebook application.

When I run the following function:

 $(document).ready(function() {
    // to show it in an alert window
    alert(window.location);

    // to store it in a variable
    var loc = window.location;
});

The returned value is the url of the inner tab, the host. Is there a way to produce the url of the outer tab using a JQuery function?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

聊慰 2024-11-17 16:58:32

也许您正在寻找parent

window.parent.location;

Maybe you're looking for parent:

window.parent.location;
梦年海沫深 2024-11-17 16:58:32

我猜你的页面是使用 Iframe 显示的?在这种情况下,由于同源策略限制,您无法对父级执行任何操作。更多信息请访问:http://en.wikipedia.org/wiki/Same_origin_policy

如果内部和外部选项卡位于同一域,请使用:

    var parentLoc = parent.location;

请注意,如果页面 URL 为“blah.facebook.com”且 facebook 应用程序加载自,则上述 JavaScript 语句将不起作用'foo.facebook.com'。

I guess your page is displayed using Iframes? In that case, you cannot do anything with the parent due to Same Origin Policy restriction. More info can be found on: http://en.wikipedia.org/wiki/Same_origin_policy.

If inner and outer tab are on same domain, use:

    var parentLoc = parent.location;

Please note that above JavaScript statement won't work in case page url is for instance 'blah.facebook.com' and the facebook application is load from 'foo.facebook.com'.

落在眉间の轻吻 2024-11-17 16:58:32

这是跨站点脚本的问题,这是不可能的。

“域、协议和端口必须匹配。”

This is an issue of cross site scripting and this isn't possible.

"Domains, protocols and ports must match."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文