how do i get url of iframe in page which contains iframe tag, when i navigate in iframe and url is changed?

118 views Asked by At

i have first domain "mydomain.com" in which i have put this

<iframe src="yourdomain.com"></iframe>

i have second domain "yourdomain.com" which contains webpages and which is in iframe src. now, i want to get url of "yourdomain.com" in "mydomain.com" when i navigate in iframe. i have already tested this code :

this.contentWindow.location

But it is not working, it is only working when both files is in same domain. so, if anybody who knows how to do this Please give me the solution and help me. Thanks in advance.

2

There are 2 answers

0
Sanjay Kumar N S On

In your yourdomain.com page try this:

window.parent.$('#iFrame').attr('src');

Where iFrame is the id of iframe tag

0
Bruce On

try this

window.top.location.src= "http://www.yourdomain.com"; 

or use this fuction

function getyourdomainUrl() {
var isInIframe = (parent !== window),
    yourdomainUrl= null;

if (isInIframe) {
    yourdomainUrl= document.referrer;
}

return yourdomainUrl;}