aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/windoweventhandlers/onafterprint/index.html
blob: be2cd99dd058e5261daf157e109454d166ae06bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
---
title: WindowEventHandlers.onafterprint
slug: Web/API/WindowEventHandlers/onafterprint
tags:
  - 打印
translation_of: Web/API/WindowEventHandlers/onafterprint
---
<div>{{ApiRef}}</div>

<p>{{domxref("WindowEventHandlers")}}的onafterprint属性是用于处理当前窗口的{{event("afterprint")}}事件的{{event("Event_handlers", "event handler")}}。这些事件会在被用户打印结束或者中止打印窗口的情况下触发。</p>

<p>{{event("beforeprint")}}<code>afterprint</code> 事件允许页面在打印开始前修改它们的内容(比如移除一个横幅等),打印结束后,这些修改会恢复原状。一般情况下,你更喜欢使用 <code><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries#Media_types">@media print</a></code> CSS规则,但是在某些情况下这些事件会有他们的必要性。</p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox"><em>window</em>.addEventListener("afterprint", function(event) { ... });
<em>window</em>.onafterprint = <em>event handling code</em>
</pre>

<h2 id="提示">提示</h2>

<p>某些浏览器(包括 Firefox 6 及更高版本和 Internet Explorer)用触发<code>beforeprint</code><code>afterprint</code>的方式来确定何时进行了打印。你可以在打印期间用这个方式来调整用户界面(UI)的表现(比如在打印过程中展示或隐藏一些界面元素)。</p>

<p><code>afterprint</code>会在用户打印完成或取消打印会话后触发。</p>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification 规范</th>
   <th scope="col">Status 状态</th>
   <th scope="col">Comment 备注</th>
  </tr>
  <tr>
   <td>{{SpecName('HTML WHATWG', '/multipage/webappapis.html#windoweventhandlers', 'onafterprint')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td></td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Edge</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>6.0</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android Webview</th>
   <th>Chrome for Android</th>
   <th>Edge</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="更多请见">更多请见</h2>

<ul>
 <li>{{domxref("window.print")}}</li>
 <li>{{domxref("window.onbeforeprint")}}</li>
 <li><a href="/en-US/docs/Printing" title="Printing">Printing</a></li>
</ul>

<div class="grammarly-disable-indicator"></div>