Javascript Iframe innerHTML

后端 未结 10 2597
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 07:08

Does anyone know how to get the HTML out of an IFRAME I have tried several different ways:

document.getElementById(\'iframe01\').contentDocument.body.innerHT         


        
10条回答
  •  清酒与你
    2020-11-27 07:50

    I think this is what you want:

    window.frames['iframe01'].document.body.innerHTML 
    

    EDIT:

    I have it on good authority that this won't work in Chrome and Firefox although it works perfectly in IE, which is where I tested it. In retrospect, that was a big mistake

    This will work:

    window.frames[0].document.body.innerHTML 
    

    I understand that this isn't exactly what was asked but don't want to delete the answer because I think it has a place.

    I like @ravz's jquery answer below.

提交回复
热议问题