Is it possible to determine whether a page will be modified by a specific domain?

Is it possible to verify that the iframed page is for a specific domain with JavaScript?

Like this:

if (window!=window.top){
   if (this page is iframed by www.foo.com){ // load foo special navigation bar}
   if (this page is iframed by www.bar.com){ // load bar special navigation bar}
} else { //load normal navigation bar }
+3
source share
2 answers

Try

var parentLocation='';
if(window.parent && document.referrer)
    parentLocation = document.referrer;
alert(parentLocation);

You should see the URL of the parent page in the warning field. And the rest, as they say, is history ...

+3
source

The EDIT / the UPDATE: . Although you can get the domain name of the parent iframe, I did not want to delete this answer, as there is some useful information for understanding the same domain policy in terms of access to the DOM. Soumya92's answer proves that an iframe in one domain can indeed get the domain of the parent domain.

However, other DOM access information is still retained.

, , , - , document.domain. .

, foo.example.com bar.example.com DOM, HTML document.domain :

// allow foo.example.com and bar.example.com to communicate
document.domain = "example.com";  

, www.foo.com , www.bar.com, , iframe top.window.

, iframe , , , , .

, - , .

0

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


All Articles