Home > Article > Web Front-end > How to use javascript print method
In JavaScript, the print() method is used to print the contents of the current window. Calling this method will generate a dialog box, allowing the user to cancel or customize the print request; the syntax format is "window.print()" .
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
javascript print() method
The print() method is used to call the printer function to print the contents of the current window, which is the same as clicking the browser's The print button works the same. Typically, this results in a dialog box that allows the user to cancel or customize the print request.
The syntax is as follows:
window.print()
Example: In the following example, click the Print current page button, and the printing interface will appear:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <p>一些文字内容......</p> <button onclick="window.print()">打印当前页面</button> </body> </html>
Browser support
For more programming-related knowledge, please visit: Programming Video! !
The above is the detailed content of How to use javascript print method. For more information, please follow other related articles on the PHP Chinese website!