How to open a document Fragment in a new tab

What options exist for opening a document fragment in a new tab or window. Which of them are the most compatible with the browser and which are the most convenient for the user?

var frag = document.createDocumentFragment();
var div = $("<div>").addClass("Printable");
div[0].innerHTML = doc.body.innerHTML;
frag.appendChild(div[0]);
openIt(frag); // How to implement openIt

A snippet contains a reformatted subset of a page that is ready for printing. A.

I would like it to naturally open through some <link>or <a>look like any friendly html link, and then quietly open the annoying popup through window.open.

+3
source share
2 answers

window.open(), document, ( . :

var win = window.open("","myWindow","...options...");
var frag = win.document.createDocumentFragment();
var div = win.document.createElement("div");
div.className = "Printable";
div.innerHTML = doc.body.innerHTML;
frag.appendChild(div);

.

+2

. window.open('data:text/html;charset=utf-8,text%20to%20show');

:

... :

var text = "<div class='Printable'>" + $("body").html() + "</div>";
window.open('data:text/html;charset=utf-8,'+text);
+1

Source: https://habr.com/ru/post/1784696/


All Articles