如何使用javascript从iframe中提取链接 [英] How extract links from iframe using javascript
本文介绍了如何使用javascript从iframe中提取链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例:
iframe.html
iframe.html
<a href="http://www.google.com">Google</a>
bla bla bla
<a href="http://www.yahoo.com">Yahoo</a>
index.html
index.html
<script>
...
</script>
There are the links from "iframe.html"
http://www.google.com
http://www.yahoo.com
推荐答案
如果域,协议和端口匹配,只需使用...
If the domain, protocol and ports match, just use...
var links = $('iframe:first').contents()[0].links;
jsFiddle 。
...或没有jQuery ......
...or without jQuery...
var iframe = document.getElementsByTagName('iframe')[0],
doc = iframe.contentDocument || iframe.contentWindow.document;
var links = doc.links;
jsFiddle 。
这利用了 document.links
property。
This takes advantage of the document.links
property.
这篇关于如何使用javascript从iframe中提取链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文