JSFiddle - React, Tailwind, and code Playground

by Valentin Sarychev

JavaScript

// печать через фрейм
// NOTE работает в спец. браузере
function iframePrint(html) {
  var iframe = document.createElement('iframe');
  iframe.style.display = 'none';
  document.body.appendChild(iframe);
  iframe.contentWindow.document.write(html);
  iframe.contentWindow.print();
  iframe.remove();
}

// печать через окно
// NOTE не работает в спец. браузере: печать прекращается, как только закрывается окно
function windowPrint(html) {
  var w = window.open();
  w.document.open();
  w.document.write(html);
  w.document.close();
  w.print();
  w.close();
}

// напечатать документ
var xhr = new XMLHttpRequest();
xhr.onload = function() {
  iframePrint(this.responseText);
  //windowPrint(this.responseText);
}
xhr.open('GET', 'https://gist.githubusercontent.com/dizel3d/d0d890d271d36400e0659f4462e7e919/raw/480f7e09ef58d32adc5a8195241c61c6d33cf5e7/exportfile_8str.html');
xhr.send();