aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/windoweventhandlers/onafterprint/index.html
blob: 8d5e46f2aa54d6e36e076d2bd80191fbe7694839 (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
---
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>

{{Compat("api.WindowEventHandlers.onafterprint")}}

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