Search code examples
javascriptsame-origin-policy

Get top window url from frame/iframe in different domain


I have a web page with some javascript inside that will be embedded as iframe in different websites. I need to adjust the behaviour of my page according to the website in which it's being run. For this purpose, I tried to read top.location.href from my page, but that raised an error:

Unsafe JavaScript attempt to access frame with URL http://website.url from frame with URL http://mypage.url. Domains, protocols and ports must match.

Is there some way to go around this?


Solution

  • This is as you stated the same origin policy and it is in place for security reasons. Without changing the users browser there is no way around it.