How extract links from iframe using javascript

前端 未结 2 2013
悲哀的现实
悲哀的现实 2020-12-21 22:22

Example:

iframe.html

Google
bla bla bla
Yahoo
         


        
2条回答
  •  Happy的楠姐
    2020-12-21 22:46

    If the domain, protocol and ports match, just use...

    var links = $('iframe:first').contents()[0].links;
    

    jsFiddle.

    ...or without jQuery...

    var iframe = document.getElementsByTagName('iframe')[0],
        doc = iframe.contentDocument || iframe.contentWindow.document; 
    
    var links = doc.links;
    

    jsFiddle.

    This takes advantage of the document.links property.

提交回复
热议问题