开发者

How to create a new HTMLDocument in IE?

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 开发者_如何学Pythonstuff!) 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜