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
1 Answer
Reset to default 6due 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