getElementById from iframe

后端 未结 2 1084
梦谈多话
梦谈多话 2020-12-19 07:38

could someone help me to understand why this errors

document.getElementById(\"actContentToGet\").contentWindow.document.body.getElementById is not

相关标签:
2条回答
  • 2020-12-19 07:54

    Try removing the body.- getElementById() is a document. function.

    0 讨论(0)
  • 2020-12-19 07:57

    Try changing this:

    ...contentWindow.document.body.getElementById(elementID)...
    

    to this:

    ...contentWindow.document.getElementById(elementID)...
    

    Edit from comments: It's not removing that element because that's not how you remove elements. Try this:

    var iframe = document.getElementById('actContentToGet');
    var frameDoc = iframe.contentDocument || iframe.contentWindow.document;
    var el = frameDoc.getElementById(elementID);
    el.parentNode.removeChild(el);
    

    See the documentation here.

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