js怎么获取iframe里面的html内容

2025-02-02 13:48:04
推荐回答(1个)
回答1:

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

iframe加载完成事件

var iframe = document.getElementById('myFrame');
if (iframe.attachEvent) {
    iframe.attachEvent("onload", function () {
        console.log(iframe.contentWindow.document.body.innerHTML);
    });
} else {
    iframe.onload = function () {
        console.log(iframe.contentWindow.document.body.innerHTML);
    };
}