I have some values in my screen , i need to print(through printer) only values in the screen by using JavaScript or j query , Is there is any inbuilt function ? except print();
Thanks as advance.
I have some values in my screen , i need to print(through printer) only values in the screen by using JavaScript or j query , Is there is any inbuilt function ? except print();
Thanks as advance.
There is no way to print some data directly, but you can use a work around method to do it
Try this function
function print_specific_content() {
var content = "Printed using Ahmed El-Essawy Code";
var win = window.open('', '', 'left=0,top=0,width=800,height=800,toolbar=0,scrollbars=0,status =0');
win.document.write("<html><body onload=\"window.print(); window.close();\">" + content + "</body></html>");
win.document.close();
}
AFAIU you want to SEND values to printer. If it's not the case please report back.
Javascript is traditionally a client-side language, so you don't have direct access to hardware. However with the advent of server javascript libraries (like Node.js) you do have server modules (as node-printer) that allow you to print things (like the examples in this answer: Node.js : How to add print job to printer)
So you would have to have a Node.js module that do the printing you want, and you would have to call it with and ajax function or something to print the values.
Hope I clarified.
You can print your specific text from the web page by using CSS @media print
Here is an example :
HTML:
<body>
<div class="doNotPrint"></div>
<div class="printThisSection">
<!-- HERE IS THE HTML CODES FOR PRINT-->
</div>
<div class="doNotPrint"></div>
</body>
CSS :
@media print{
.doNotPrint{ /*This section will never print*/
display: none;
}
/*Your other CSS property here*/
}
Note : You can use shortcut
ctrl
+
p
to show print popup instead of usingwindow.print()