Skip to content

Instantly share code, notes, and snippets.

@Maes95
Created October 5, 2019 16:50
Show Gist options
  • Save Maes95/4b061c8fdbbe13e4e33e793f1191106d to your computer and use it in GitHub Desktop.
Save Maes95/4b061c8fdbbe13e4e33e793f1191106d to your computer and use it in GitHub Desktop.
function printElementSimple(elem){
w=window.open();
w.document.write($(elem).html());
w.print();
w.close();
}
document.getElementById('preview-viewer').contentWindow.print()
function printElement(elem, style){
if (document.getElementById != null){
var html = '<HTML>\n<HEAD>\n';
if (document.getElementsByTagName != null){
var headTags = document.getElementsByTagName("head");
if (headTags.length > 0) {
html += headTags[0].innerHTML;
}
}
html += "<STYLE>"+style+"</STYLE>";
html += '\n</HEAD>\n<BODY>\n';
var elem = elem
if (elem != null) html += elem.innerHTML;
else{
alert("Error, no contents.");
return;
}
html += '\n</BODY>\n</HTML>';
var printWin = window.open("","PrintWindow");
printWin.document.open();
printWin.document.write(html);
printWin.document.close();
//printWin.print();
} else alert("Browser not supported.");
}
var style = "td span, td del, td ins { word-break: break-word;} del { color: #000; background: #f88; text-decoration: none;} ins {color: #000; background: #9f9; text-decoration: none;}"
printElement($('.pad-top-md>.ng-star-inserted'),style);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment