开发者

How to get url of the website in iframe?

how can i get url of the we开发者_运维百科bsite 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.


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();


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜