Getting Contents of Iframe with Pure JavaScript

前端 未结 1 1468
说谎
说谎 2020-12-01 23:20

I already can get the content of an Iframe with jQuery, though I would like to learn how to get it with pure JavaScript.

This is what I have so far.

         


        
相关标签:
1条回答
  • 2020-12-02 00:12

    If it is on the same domain, try this. It won't let you access iframe contents if the iframe is of a different origin than the window that you are viewing.

    var iframe = document.getElementById("awc_frame");
    var iframe_contents = iframe.contentDocument.body.innerHTML;
    

    Working example with jsfiddle iframe viewing a page on the same domain:

    http://jsfiddle.net/tqAL3/1/

    0 讨论(0)
提交回复
热议问题