Home >Web Front-end >JS Tutorial >How to use javascript print method

How to use javascript print method

青灯夜游
青灯夜游Original
2021-06-07 17:39:5910470browse

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

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>

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!

Statement:
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