Get HTML inside iframe using jQuery

后端 未结 10 1187
清歌不尽
清歌不尽 2020-11-27 04:24

Here is my situation.

I have a file called iframe.html, which contains the code to for a image slideshow. The code is somewhat like

<         


        
10条回答
  •  佛祖请我去吃肉
    2020-11-27 05:08

    This line will retrieve the whole HTML code of the frame. By using other methods instead of innerHTML you can traverse DOM of the inner document.

    document.getElementById('iframe').contentWindow.document.body.innerHTML
    

    Thing to remember is that this will work only if the frame source is on the same domain. If it is from a different domain, cross-site-scripting (XSS) protection will kick in.

提交回复
热议问题