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?
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>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments