How can I access the parent DOM from an iframe in another domain?

I have a website and my domain is registered through Network Solutions (whom I would recommend not ). I use the web-forwarding function, which allows me to “mask” my domain so that when a user visits http://lucasmccoy.com they actually see http://lucasmccoy.comlu.com/ through an HTML frame. The advantages of this is that the address bar is still showing http://lucasmccoy.com/.

The disadvantages are that I cannot directly edit the HTML page in which the frame is located. For example, I cannot change the page name or icon. I tried to do it like this:

$(function() {
    parent.document.title = 'Lucas McCoy';
});

But of course this gives me a JavaScript error:

Unsafe JavaScript attempt to access frame with URL http://lucasmccoy.com/ from frame with URL http://lucasmccoy.comlu.com/. Domains, protocols and ports must match.

I reviewed this question while trying to do the same, except that the OP has access to other HTML pages, while I do not.

Is it in JavaScript / jQuery to make a cross-domain query in the DOM when you do not have access to this domain? Or is this something that browsers simply will not allow for security reasons.

+3
source share
1 answer

No. Most browsers implement the same origin policy .

+5
source

Source: https://habr.com/ru/post/1741694/


All Articles