Reposition top window from iframe

Hello, I want to redirect my Facebook application page to another application page using php and javascript

I have

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

But I get an error message:

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

Is it possible to redirect from the iFrame Facebook application without any problems?

+4
source share
1 answer

due to XSS restrictions which you can set but cannot read top.location.href if your iframe is in a different domain than the page calling the iframe. If the page you are redirecting to has the same domain name, you can check top.location.href. Thus, the logic, if your code should be canceled, checks if it can access top.location.href and if NOT redirected. put it in a try..catch block to avoid javascript errors when accessing top.location

+6
source

All Articles