- var printContents = document.getElementById("bodyID").innerHTML;
- var originalContents = document.body.innerHTML;
- document.body.innerHTML = printContents;
- var mywindow = window.open('', 'my div', 'height=400,width=600');
- mywindow.document.write('<html><head><title></title>');
-
- mywindow.document.write('</head><body >');
- mywindow.document.write(printContents);
- mywindow.document.write('</body></html>');
- mywindow.document.close();
- mywindow.focus();
- mywindow.print();
- mywindow.close();
- document.body.innerHTML = originalContents;
- window.location.href = "/Home/Index"
Suppose you are on the Home page, you want some other page data to be printed, then navigate on click of the print icon to the print page and then Add a JS file onto that Print page with the above script code.
This will surely help ..:).