Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Window: beforeprint event

BaselineWidely available

Thebeforeprint event is fired when the associated document is about to be printed or previewed for printing.

Theafterprint andbeforeprint events allow pages to change their content before printing starts (perhaps to remove a banner, for example) and then revert those changes after printing has completed. In general, you should prefer the use of a@media print CSS at-rule, but it may be necessary to use these events in some cases.

Syntax

Use the event name in methods likeaddEventListener(), or set an event handler property.

js
addEventListener("beforeprint", (event) => { })onbeforeprint = (event) => { }

Event type

A genericEvent.

Examples

UsingaddEventListener():

js
window.addEventListener("beforeprint", (event) => {  console.log("Before print");});

Using theonbeforeprint event handler property:

js
window.onbeforeprint = (event) => {  console.log("Before print");};

Specifications

Specification
HTML
# event-beforeprint
HTML
# handler-window-onbeforeprint

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp