最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Change top window location from iframe - Stack Overflow

programmeradmin1浏览0评论

Hello I want to redirect my Facebook App page to another app page using php and javascript

I have

echo "<script type='text/javascript'>
if(window.top.location.href.toLowerCase().indexOf('/') != -1) {
    window.top.location.href = '/';
    alert("Done");
}
else
   alert(window.top.location.href); 
</script>";

But I get an error:

Unsafe JavaScript attempt to access frame with URL /?ref=bookmarks from frame with URL /?ref=bookmarks. Domains, protocols and ports must match.

Is it possible to redirect from the Facebook Application iFrame without any problem?

Hello I want to redirect my Facebook App page to another app page using php and javascript

I have

echo "<script type='text/javascript'>
if(window.top.location.href.toLowerCase().indexOf('http://apps.facebook./app1/') != -1) {
    window.top.location.href = 'http://apps.facebook./app2/2/';
    alert("Done");
}
else
   alert(window.top.location.href); 
</script>";

But I get an error:

Unsafe JavaScript attempt to access frame with URL http://apps.facebook./myapp/?ref=bookmarks from frame with URL http://mydomain./?ref=bookmarks. Domains, protocols and ports must match.

Is it possible to redirect from the Facebook Application iFrame without any problem?

Share Improve this question asked Aug 7, 2011 at 13:49 ImmoImmo 6011 gold badge6 silver badges19 bronze badges 1
  • 1 I think you can redirect, but you can't check the url of top window. But I think you can check for document.referrer – Karolis Commented Aug 7, 2011 at 14:09
Add a ment  | 

1 Answer 1

Reset to default 6

due to XSS-resrictions you can set but cannot read top.location.href if your iframe resides on another domain than the page that calls the iframe. If the page you are redirecting to has the same domainname you will be able to check top.location.href. So the logic if your code should be reversed checking if it can access top.location.href and if NOT redirect. put it in a try..catch block to avoid javascript errors when accessing top.location

发布评论

评论列表(0)

  1. 暂无评论