tags:

views:

54

answers:

3

hi,

how can i get url of the website which is in iframe, when i click on any links in website in iframe it is redirect to another page in the iframe then how can i get the page url. can u help me. thank you.

A: 

Unfortunately, you don't really have much control over an Iframe once it loads. I think pretty much the only thing you have control over is the ability to reload it with a new URL programatically.

If the page loaded by the Iframe is part of your website (not 3rd party), you can process the request server-side.

Ash White
A: 

From javascript? If you can run some JS inside the iframe:

alert(document.location.href);

If you can't - need to get a reference to the iframe in question:

IE:

alert(document.getElementById(iframeId).contentWindow.document.location.href);

FF, Safari, Chrome, etc:

alert(document.getElementById(iframeId).contentDocument.location.href);

As mentioned - you wont be able to do this if the URL that is loaded is not from the same domain as your website.

Adam
@Adam when i write document.getElementById('myIframe').src;it is giving site url, but when i move to another page in the same site i am not getting full path of the site every time it is showing the initial url of the site but i want total url, when i move to another page in the same site. for example in my iframe i have amazon site if i click on BOOKS in amazon it is redirect to another page in the same site, i want the url of the page how can i get the url of the page. Thank u for response
Surya sasidhar
try: document.getElementById('myIframe').contentWindow.document.location.href ORdocument.getElementById('myIframe').contentDocument.location.href
Adam
+1  A: 

You can use jquery to make it easier:

alert($("#iframeid").attr("src"));

You can also use jquery contents() to retrieve or manipulate any tags inside that iframe. example:

$("#iframeid").contents().find("a").css("background-color","red").end().find("title").text();
Mouhannad