Inside a facebook application I need to check what is the top frame (the main window) URL, and show content accordingly.
I tried using the following:
if (top.location.toString().toLowerCase().indexOf("facebook.com") <0) { ... }
Which works well if the page is not inside an iframe, but when the page is loaded within an iframe (as it does when used as facebook application) the code generates
“Uncaught TypeError: Property
‘toString’ of object # is not a
function”.
Is there any way I can fix this code (with cross-browser compatibility – maybe with jQuery)?
Thanks!
Joel
The problem you are having that you are not allowed to access
top.locationacross different document domains.This is a security feature built in to browsers.
Read up on XSS and why the security precautions are in place 🙂
You can also learn a great deal by reading about the same origin policy