Home Web Front-end JS Tutorial JS call printer function sample code

JS call printer function sample code

Jul 13, 2017 pm 03:22 PM
javascript code printer

Sometimes the printing function needs to be added to the front-end project. First of all, you must know that printing is divided into two types: overall printing and partial printing. Partial printing can be subdivided into partial printing of the specified part, and partial printing of the specified part. part. Examples look clearer than text.

The examples in this article describe how JS calls the printer function. Share it with everyone for your reference, the details are as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><!--{$aListData.name}-->准考证</title>
<input id="btnPrint" type="button" value="打印" onclick="javascript:window.print();" />
<input id="btnPrint" type="button" value="打印预览" onclick=preview(1) />
<style type="text/css" media=print>
.noprint{display : none }
</style>
<script>
function preview(oper)
{
if (oper < 10)
{
bdhtml=window.document.body.innerHTML;//获取当前页的html代码
sprnstr="<!--startprint"+oper+"-->";//设置打印开始区域
eprnstr="<!--endprint"+oper+"-->";//设置打印结束区域
prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //从开始代码向后取html
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//从结束代码向前取html
window.document.body.innerHTML=prnhtml;
window.print();
window.document.body.innerHTML=bdhtml;
} else {
window.print();
}
}
</script>
<script type="text/javascript" src="/js/jquery-1.4.2.min.js"></script>
<script>
jQuery(function($){
 $("#closeButton").click(function(){
    window.close();
 })
});
</script>
</head>
<body>
<a id=&#39;closeButton&#39; title=&#39;Close&#39; href="#" >关闭</a>
<!-- 打印startprint与endprint之间的内容-->
<!--startprint1-->
<h1>高级中学2013年预科招生考试</h1>
姓名:<!--{$aListData.name}--><br/>
性别:<!--{$aListData.gender}--><br/>
毕业学校:<!--{$aListData.grschool}--><br/>
编号:<input type="text" name="sturegcard" class="input1 ml10" value="<!--{$aListData.sturegcard}-->"/><br/>
头像:<img src="<!--{$aListData.avatar}-->" width="140"><br/>
考试日程:<br/>
地点:<br/>
<!--{if $aRegExamsche}-->
  <!--{section name=data loop=$aRegExamsche}-->
    <!--{$aRegExamsche[data].date}-->
    <!--{$aRegExamsche[data].time}-->
    <!--{$aRegExamsche[data].lesson}-->
    <!--{$aRegExamsche[data].place}--><br/>
  <!--{/section}-->
<!--{/if}-->
<!--endprint1-->
</body>
</html>
Copy after login

The above is the detailed content of JS call printer function sample code. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Printer has insufficient memory and cannot print the page Excel or PowerPoint error Printer has insufficient memory and cannot print the page Excel or PowerPoint error Feb 19, 2024 pm 05:45 PM

If you encounter the problem of insufficient printer memory when printing Excel worksheets or PowerPoint presentations, this article may be helpful to you. You may receive a similar error message stating that the printer does not have enough memory to print the page. However, there are some suggestions you can follow to resolve this issue. Why is printer memory unavailable when printing? Insufficient printer memory may cause a memory not available error. Sometimes it's because the printer driver settings are too low, but it can also be for other reasons. Large file size Printer driver Outdated or corrupt Interruption from installed add-ons Misconfiguration of printer settings This issue may also occur because of low memory settings on the Microsoft Windows printer driver. Repair printing

Unable to complete operation (Error 0x0000771) Printer error Unable to complete operation (Error 0x0000771) Printer error Mar 16, 2024 pm 03:50 PM

If you encounter an error message when using your printer, such as the operation could not be completed (error 0x00000771), it may be because the printer has been disconnected. In this case, you can solve the problem through the following methods. In this article, we will discuss how to fix this issue on Windows 11/10 PC. The entire error message says: The operation could not be completed (error 0x0000771). The specified printer has been deleted. Fix 0x00000771 Printer Error on Windows PC To fix Printer Error the operation could not be completed (Error 0x0000771), the specified printer has been deleted on Windows 11/10 PC, follow this solution: Restart Print Spool

Can't print from snipping tool in Windows 11/10 Can't print from snipping tool in Windows 11/10 Feb 19, 2024 am 11:39 AM

If you are unable to print using the Snipping Tool in Windows 11/10, it may be caused by corrupted system files or driver issues. This article will provide you with solutions to this problem. Can't print from Snipping Tool in Windows 11/10 If you can't print from Snipping Tool in Windows 11/10, use these fixes: Restart PC Printer Clear print queue Update printer and graphics driver Fix or reset Snipping Tool Run SFC and DISM Scan uses PowerShell commands to uninstall and reinstall Snipping Tool. let us start. 1] Restart your PC and printer Restarting your PC and printer helps eliminate temporary glitches

What should I do if WPS cannot start the printer job? What should I do if WPS cannot start the printer job? Mar 20, 2024 am 08:20 AM

We can use office software to produce various electronic documents. Electronic documents greatly save the use of paper and are easier to save and read. However, sometimes according to work requirements, superiors require printing out paper documents for everyone to circulate. Document writing It's fine but unable to print. It's very difficult to encounter such a situation. The course we brought today can solve this problem. The following lesson is: What should I do if WPS cannot start the printer job? When trying to print a document using a LAN printer, a problem occurred, saying &quot;WPSOffice cannot start the print job. Please check whether the printer is turned on and online.&quot; But in fact, the printer is powered on and online. 2. Click &quot;OK&quot;, then click on the upper left corner of the title bar as shown in the picture

What to do if the blue screen code 0x0000001 occurs What to do if the blue screen code 0x0000001 occurs Feb 23, 2024 am 08:09 AM

What to do with blue screen code 0x0000001? The blue screen error is a warning mechanism when there is a problem with the computer system or hardware. Code 0x0000001 usually indicates a hardware or driver failure. When users suddenly encounter a blue screen error while using their computer, they may feel panicked and at a loss. Fortunately, most blue screen errors can be troubleshooted and dealt with with a few simple steps. This article will introduce readers to some methods to solve the blue screen error code 0x0000001. First, when encountering a blue screen error, we can try to restart

Lenovo Xiaoxin Panda Pro Panda Printer Pro goes on sale on May 6: black and white laser printing, built-in learning resources, 999 yuan Lenovo Xiaoxin Panda Pro Panda Printer Pro goes on sale on May 6: black and white laser printing, built-in learning resources, 999 yuan May 01, 2024 am 08:46 AM

According to news from this site on April 30, Lenovo Xiaoxin PandaPro Panda Printer Pro is now available on JD.com. This printer will go on sale on May 6. It supports black and white laser printing, has an optional two-color body, and has built-in learning resources. The initial price is 999. Yuan. Lenovo Xiaoxin Panda Printer Pro measures 350x275x141mm and is available in two color options: Xiling White and Qingcheng Gray. This printer supports 2.4GHz/5GHz dual-band Wi-Fi, USB wired and other connection methods. It can print with one click after being configured with the network, and can also achieve NFC one-touch printing. Xiaoxin Panda Printer Pro supports black and white laser printing and can print 22 pages per minute. In addition to printing functions, this model also supports copying and scanning functions, with a color scanning resolution of 4800d.

The Print Spooler service automatically shuts down and the printer cannot print normally. The Print Spooler service automatically shuts down and the printer cannot print normally. Jun 18, 2024 pm 08:20 PM

My friend's printer suddenly stopped printing. When WPS was printing, it prompted "The system print service has been closed" and "The system PrintSpooler service has been detected to be closed. Please enable it and try again." The PrintSpooler service executes print jobs in the background and handles interactions with the printer. . If you turn off the service, you cannot print or view the printer. According to the prompts, generally we only need to find the PrintSpooler service in the service, start it and change it to automatic. After my friend's computer started the PrintSpooler service, the service automatically stopped in about a minute and started again, and the same situation occurred. Saw spoolsv.exe and a dl through event viewer

Mobile phone directly connected to printer (explore various connection methods of mobile phone connected directly to printer) Mobile phone directly connected to printer (explore various connection methods of mobile phone connected directly to printer) Apr 25, 2024 pm 07:31 PM

Direct-connection of mobile phone printers has become an increasingly popular printing solution in modern life, as mobile devices become more popular and their functions continue to increase. To quickly print files, we can directly connect to the printer through our mobile phones without the need for a computer. To help you choose the printing solution that best suits your needs, this article will introduce you to the various connection methods for direct connection of your mobile phone to the printer. Wi-Fi direct printing Wi-Fi direct printing is currently one of the most common methods of directly connecting a mobile phone to a printer. By connecting the printer and mobile phone to the same Wi-Fi network, users can easily transfer and print files through the mobile app. Bluetooth direct printing Bluetooth direct printing is a simpler and more convenient way to connect a mobile phone directly to a printer. can realize the file

See all articles