How to create a new HTMLDocument in IE?

ぐ巨炮叔叔 提交于 2020-01-04 03:51:31

问题


dcoument.implementation.createHTMLDocument [2] is one of the lesser-known DOM methods that (surprise!) creates a brand new HTML document.

Unsurprisingly, browser support is rather poor, but I found some workarounds:

  • Use an XLSTProcessor (crazy stuff!) in Firefox < 4
  • Create an empty iFrame:

    var iframe = document.createElement('iframe');
    iframe.style = 'display: none';
    iframe.src = 'data:text/html,<!DOCTYPE html><title></title><body>';
    document.body.appendChild(iframe);
    newHTMLDocument = iframe.contentDocument; // <- we need this.
    document.body.removeChild(iframe);
    

Still, since IE does not support the data scheme on iframes, there is no way to do it in IE. Or is there?


回答1:


How about setting src to about:blank?
(And perhaps document.writeing an empty HTML document)



来源:https://stackoverflow.com/questions/4935664/how-to-create-a-new-htmldocument-in-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!