简体   繁体   中英

JQuery Get Parent URL in IFrame:iframe and its parent are in Different domain

I am struggling to get parenet URL inside my iframe (ie the url showing in browser). My parent site is gslb13.aaa.com .Inside there is an iframe in which i am loading my site test.elasticbeanstalk.com (notice both are in different domain) Onclicking smile link in gslb13.aaa.com . It will load test.elasticbeanstalk.com inside iframe.

To get the parent url I tried with

var url = (window.location != window.parent.location) ? document.referrer: document.location;
alert(url);

I am getting the parent URL in index page of test.elasticbeanstalk.com (on load). then:

1) I clicked "Add" buttons in the test.elasticbeanstalk.com to go to next view

2) Repeated the same code in add.jspx to get the same parent URL

But unfortunately I am getting the URL of test.elasticbeanstalk.com(Not Parent URL:gslb13.aaa.com )

Can Any one suggest me a way to handle this?

use

document.referrer;

Refer This

You cannot.

The same origin security rules prohibit it. http://en.wikipedia.org/wiki/Same-origin_policy

You need to pass the URL of the parent page with the get request, ortherwise there is no reliable way to get the "parent" url.

You would need the iframe like this:

<script type="text/javascript">
url = encodeURIComponent(document.location.href);
document.write('<iframe src="http://test.elasticbeanstalk.com/something.php?refer='+url+'"></iframe>');
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM