Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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?

like image 588
user123444555621 Avatar asked Feb 21 '26 05:02

user123444555621


1 Answers

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

like image 172
SLaks Avatar answered Feb 23 '26 18:02

SLaks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!