how to reload top most window from iframe?

半腔热情 提交于 2019-12-10 16:38:03

问题


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!


回答1:


We reference the facebook parent page as top.

use top.location.href=""; or top.location.reload();




回答2:


Neither top.location.href=""; or top.location.reload(); worked for me.

I had to use top.location.href="http://www.facebook.com/appurl";




回答3:


Try top.location.reload(true); instead of top.location.reload();

Extracted from http://www.w3schools.com/jsref/met_loc_reload.asp:

By default, the location.reload() method reloads from the cache, but by you can force the the reload to get the page from server by setting the forceGet parameter to true: location.reload(true).




回答4:


To reload you could use top.location.href = top.location.href;



来源:https://stackoverflow.com/questions/5943894/how-to-reload-top-most-window-from-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!