यदि आप इस बिंदु तक स्क्रॉल करना चाहते हैं, तो मुझे फ़ायरफ़ॉक्स के लिए एक समाधान मिला। यह पाद और हेडर के बिना एक विशिष्ट div से सामग्री प्रिंट करेगा। आप अपनी इच्छानुसार कस्टमाइज़ कर सकते हैं।
सबसे पहले, इस ऐडऑन को डाउनलोड और इंस्टॉल करें: JSPrintSetup ।
दूसरे, इस फ़ंक्शन को लिखें:
<script>
function PrintElem(elem)
{
var mywindow = window.open('', 'PRINT', 'height=400,width=600');
mywindow.document.write('<html><head><title>' + document.title + '</title>');
mywindow.document.write('</head><body >');
mywindow.document.write(elem);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10*/
//jsPrintSetup.setPrinter('PDFCreator'); //set the printer if you wish
jsPrintSetup.setSilentPrint(1);
//sent empty page header
jsPrintSetup.setOption('headerStrLeft', '');
jsPrintSetup.setOption('headerStrCenter', '');
jsPrintSetup.setOption('headerStrRight', '');
// set empty page footer
jsPrintSetup.setOption('footerStrLeft', '');
jsPrintSetup.setOption('footerStrCenter', '');
jsPrintSetup.setOption('footerStrRight', '');
// print my window silently.
jsPrintSetup.printWindow(mywindow);
jsPrintSetup.setSilentPrint(1); //change to 0 if you want print dialog
mywindow.close();
return true;
}
</script>
तीसरा, आपके कोड में, जहाँ भी आप प्रिंट कोड लिखना चाहते हैं, यह करें (मैंने JQuery का उपयोग किया है। आप सादे जावास्क्रिप्ट का उपयोग कर सकते हैं):
<script>
$("#print").click(function () {
var contents = $("#yourDivToPrint").html();
PrintElem(contents);
})
</script>
जाहिर है, आपको क्लिक करने के लिए लिंक की आवश्यकता है:
<a href="#" id="print">Print my Div</a>
और आपका div प्रिंट करने के लिए:
<div id="yourDivToPrint">....</div>