如何从 iframe 重新加载最上面的窗口?
我正在开发一个具有以下“结构”的 Facebook 应用程序:
Browser window (facebook.com/page/xxxx)
-- My app's iframe
-- Like button's iframe
我在应用程序中使用“赞”按钮,因此这是 iframe 内的 iframe,当用户单击“赞”按钮时,我想显示内容,以便该页面目前看起来像这样:
if ( is_fan() ) {
//show content
} else {
//show like button plus other text
}
检查用户是否已经是粉丝的实际逻辑正在按预期工作,问题是当我单击“喜欢”按钮时,我需要重新加载整个页面才能显示“粉丝内容” “,如果我这样做
FB.Event.subscribe('edge.create', function(href, widget) {
top.location.reload();
});
:页面似乎重新加载,但一切都保持不变,但如果我单击“喜欢”并单击浏览器中的刷新按钮,一切都会显示得很好。
谁能帮我解决这个问题吗?
提前致谢!
I'm developing a facebook app which has the following "structure":
Browser window (facebook.com/page/xxxx)
-- My app's iframe
-- Like button's iframe
I'm using a Like button within my app so that's an iframe inside an iframe, when the users clicks on the like button I'd like to show the content so the page currently looks somethin like this:
if ( is_fan() ) {
//show content
} else {
//show like button plus other text
}
The actual logic to check if the user is already a fan is working as intended, the problem is that when I click the like button I need the whole page to reload in order to show the "fan content", if I do this:
FB.Event.subscribe('edge.create', function(href, widget) {
top.location.reload();
});
The page seems to reload but everything stays the same, but if I click "Like" and the click the refresh button in my browser everything shows up just fine.
Can anyone help me figure this out?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我们将 Facebook 父页面引用为
top
。使用
top.location.href="";
或top.location.reload();
We reference the facebook parent page as
top
.use
top.location.href="";
ortop.location.reload();
top.location.href="";
或top.location.reload();
都不适合我。我必须使用
top.location.href="http://www.facebook.com/appurl";
Neither
top.location.href="";
ortop.location.reload();
worked for me.I had to use
top.location.href="http://www.facebook.com/appurl";
尝试使用
top.location.reload(true);
而不是top.location.reload();
摘自 http://www.w3schools.com/jsref/met_loc_reload.asp:
Try
top.location.reload(true);
instead oftop.location.reload();
Extracted from http://www.w3schools.com/jsref/met_loc_reload.asp:
要重新加载,您可以使用
top.location.href = top.location.href;
To reload you could use
top.location.href = top.location.href;