从 Facebook 画布页面重定向到网站 [英] Redirect from Facebook canvas page to website

查看:22
本文介绍了从 Facebook 画布页面重定向到网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从我的 Facebook 画布页面重定向到我的外部网站?我看过以下形式的博客和 stackoverflow 答案:

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>

不幸的是,这些解决方案从未奏效.我也试过 top.location.href、window.location 和 location.href ......没有任何效果.Facebook 是否通过解析这种代码消除了从 javascript 重定向的可能性?有没有办法仍然重定向?

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:网页表现得好像从来没有 javascript 重定向指令一样.事实上,当我通过 firebug 查看源代码时,我看不到 javascript 重定向.

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:当我尝试 window.top.location = 'http://www.yoursite.com/'; 和上面的其他变体.Facebook 似乎不允许访问窗口、顶部或位置全局 javascript 变量:

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

有趣的是,document.location = 'http://www.yoursite.com/'; 的工作原理是没有例外......但当然网页不会被重定向.

Interestingly, document.location = 'http://www.yoursite.com/'; works in that there are no exceptions... but of course the webpage doesn't get redirected.

更新 3:想通了!Javascript 重定向仅适用于 iframe 画布.我必须更改高级屏幕中的设置才能使用 iframe 而不是 FBML.

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.

推荐答案

如何使用以下代码:

 <script type='text/javascript'>
    top.location.href = 'http://www.yousite.com';
 </script>

这篇关于从 Facebook 画布页面重定向到网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆