I am getting the below error when i try to set a hash value to the parent url from iframe which contains another domain url:
Unsafe JavaScript attempt to access frame with URL "URL1" from frame with URL "URL2". Domains, protocols and ports must match.
How can I fix this problem?
From a child document of different origin you are not allowed access to the top window's location.hash
property, but you are allowed to set the location
property itself.
This means that given that the top windows location is http://example.com/page/
, instead of doing
parent.location.hash = "#foobar";
you do need to know the parents location and do
parent.location = "http://example.com/page/#foobar";
Since the resource is not navigated this will work as expected, only changing the hash part of the url.
If you are using this for cross-domain communication, then I would recommend using easyXDM instead.
Crossframe-Scripting is not possible when the two frames have different domains -> Security.
See this: http://javascript.about.com/od/reference/a/frame3.htm
Now to answer your question: there is no solution or work around, you simply should check your website-design why there must be two frames from different domains that changes the url of the other one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With