开发者

How to get url of the website in iframe?

开发者 https://www.devze.com 2023-01-13 05:22 出处:网络
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.

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

精彩评论

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

关注公众号