未捕获的TypeError:无法读取未定义的属性'contentDocument'

时间:2015-12-05 17:06:09

标签: javascript

function init() {
    document.getElementById('step1').innerHTML = document.getElementsByTagName('iframe')[0].contentDocument.document.body.innerHTML;
    document.getElementById('code1').value = document.getElementById('google_ads_frame1').src;
    document.technical1.submit();
}
  

o erro se encontra na linha                   document.getElementById'step1 ')的innerHTML = document.getElementsByTagName(' IFRAME')的 [0] .contentDocument.document.body.innerHTML;

enter image description here

1 个答案:

答案 0 :(得分:0)

仅使用contentDocument.body代替contentDocument.document.body

document.getElementById('step1').innerHTML = document.getElementsByTagName('iframe')[0].contentDocument.body.innerHTML;

contentWindow代替contentDocument

document.getElementById('step1').innerHTML = document.getElementsByTagName('iframe')[0].contentWindow.document.body.innerHTML;

iframe.contentDocumentiframe.contentWindow.document

相同

HTML: Getting document from IFrame