Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Gábor Papp
Added: Feb 11, 2018 7:31 AM
Views: 14
Tags: no tags
  1. function nyomtatasframe(divid) {
  2.     // var contents = document.getElementById(divid).innerHTML;
  3.     var frame1 = document.createElement('iframe');
  4.     frame1.name = "frame1";
  5.     frame1.style.position = "absolute";
  6.     frame1.style.top = "-1000000px";
  7.     document.body.appendChild(frame1);
  8.     var frameDoc = frame1.contentWindow ? frame1.contentWindow : frame1.contentDocument.document ? frame1.contentDocument.document : frame1.contentDocument;
  9.    
  10.     frameDoc.document.write('<html><head><title>' + document.title  + '</title>');
  11.     frameDoc.document.write('<style type="text/css">');
  12.     frameDoc.document.write('BODY { font-size: 16px; }');
  13.     frameDoc.document.write('H1, H2 { color: #000000; }');
  14.     frameDoc.document.write('.noprint { display: none; }');
  15.     frameDoc.document.write('IFRAME { display: none; }');
  16.     frameDoc.document.write('IMG { max-width: 100%; }');
  17.     frameDoc.document.write('</style>');
  18.     frameDoc.document.write('</head><body >');
  19.     frameDoc.document.write('<h1>' + document.title  + '</h1>');
  20.     frameDoc.document.write(document.getElementById(divid).innerHTML);
  21.     frameDoc.document.write('</body></html>');
  22.    
  23.     frameDoc.document.close();
  24.  
  25.     setTimeout(function () {
  26.         window.frames["frame1"].focus();
  27.         window.frames["frame1"].print();
  28.         document.body.removeChild(frame1);
  29.     }, 500);
  30.     return false;
  31. }