So there is a parent page on one domain that includes an iframe from a different domain.
I am trying to navigate parent page from the iframe using a relative path that would take base url from the parent.
I tried with
<script type="text/javascript">
function navigateParent(targetPage) {
var url = window.parent.location.href;
if (url.indexOf('.') > -1) {
url = url.substring(0, url.lastIndexOf('/') + 1);
}
window.parent.location = url + targetPage;
}
</script>
but this produces an error:
Unsafe JavaScript attempt to access frame with URL …my parent url… with URL …my iframe url… . Domains, protocols and ports must match.
Is there any way to do this? Ie specifiying some cross-domain permission or something.
Cross domain protections are now serverly enforced browser-side to protect the user (following some cross domain injections).
To call a function or change a property in a frame/window served by another domain you can
specify CORS headers on the server (this tells the browser that cross domain communication is fine)
preferred : use postMessage to communicate between windows and frames