从Facebook画布页面重定向到网站 [英] Redirect from Facebook canvas page to website
问题描述
< script>
window.top.location ='http://www.yoursite.com/';
< / script>
不幸的是,这些解决方案永远不会工作。我已经尝试过top.location.href,window.location和location.href以及没有任何工作。通过解析出这种代码,Facebook是否可以从javascript重定向?有没有办法仍然重定向?
更新 :网页的行为如何,从来没有javascript重定向指令事实上,当我通过firebug查看源代码时,我看不到javascript重定向。
更新2 :当我尝试 window.top.location ='http://www.yoursite.com/';
和其他变体时,我的画布页面中会收到以下JavaScript错误以上。看来Facebook不允许访问窗口,顶部或位置全局javascript变量:
未捕获ReferenceError:a217374027657_location未定义
未捕获ReferenceError:a217374027657_window未定义
未捕获ReferenceError:a217374027657_top未定义
有趣的是, document.location ='http://www.yoursite.com/';
的工作原理是没有例外...但是当然网页没有
更新3 :图解出来! Javascript重定向只适用于iframe画布。我不得不在高级屏幕中更改我的设置,以使用iframe而不是FBML。
如何使用以下代码: / p>
< script type ='text / javascript'>
top.location.href ='http://www.yousite.com';
< / script>
Is there a way to redirect from my Facebook canvas page to my external website? I've seen blogs and stackoverflow answers of the form:
<script>
window.top.location = 'http://www.yoursite.com/';
</script>
Unfortunately these kinds of solutions never work. I've tried top.location.href, window.location and location.href as well.. nothing works. Did Facebook remove the possibility to redirect from javascript by parsing out this kind of code? Is there a way to still redirect?
UPDATE: What happens is the webpage acts like there was never a javascript redirect instruction. And in fact, when I look at the source code through firebug I see no javascript redirects.
UPDATE 2: I get the following javascript errors form my canvas page when I try window.top.location = 'http://www.yoursite.com/';
and the other variations above. It seems Facebook doesn't allow access to the window, top or location global javascript variables:
Uncaught ReferenceError: a217374027657_location is not defined
Uncaught ReferenceError: a217374027657_window is not defined
Uncaught ReferenceError: a217374027657_top is not defined
Interestingly, document.location = 'http://www.yoursite.com/';
works in that there are no exceptions... but of course the webpage doesn't get redirected.
UPDATE 3: Figured it out! Javascript redirect only works with iframe canvases. I had to change my settings in the advanced screen to use iframe instead of FBML.
how about using the following code:
<script type='text/javascript'>
top.location.href = 'http://www.yousite.com';
</script>
这篇关于从Facebook画布页面重定向到网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!