Home > Web Front-end > JS Tutorial > body text

How to use javascript print method

青灯夜游
Release: 2021-06-07 17:39:59
Original
10429 people have browsed it

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()" .

How to use javascript print method

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()
Copy after login

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>
Copy after login

How to use javascript print method

Browser support

How to use javascript print method

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template