English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML reference manual

HTML tag大全

HTML5 onbeforeprint event property

The beforeprint event is triggered when the associated document is about to be printed or previewed for printing.

Attributs d'événement HTML

Online Example

Execute JavaScript when the page is to be printed:

<!DOCTYPE html>
<html>
<head>
<title>HTML onbeforeprint event property usage(basic tutorial website oldtoolbag.com)</title>
<body onbeforeprint="myFunction()">
<h1>Try to print this document</h1>
<p><b>Tip:</b> Keyboard shortcuts, such as Ctrl+P sets the page to print.</p>
<p><b>Note:</b> The onbeforeprint event is not supported in Safari and Opera.</p>
<script>
function myFunction() {
  alert("Vous êtes sur le point d'imprimer ce document !");
}
</script>
</body>
</html>
Voyons si ‹/›

Compatibilité des navigateurs

IEFirefoxOperaChromeSafari

Actuellement, seuls les navigateurs Internet Explorer et Firefox prennent en charge l'attribut d'événement onbeforeprint.

Définition et utilisation

Lorsque la page va être imprimée (avant l'apparition de la boîte de dialogue d'impression), l'attribut onbeforeprint est déclenché.
Astuce : L'attribut onbeforeprint est généralement utilisé avec l'attribut onafterprint

HTML 4.01 et HTML5différences entre

L'attribut onbeforeprint est un attribut HTML5Nouvel attribut.

Syntaxe

<element onbeforeprint="script">

Valeur de l'attribut

ValeurDescription
scriptScript exécuté dans onafterprint.
Attributs d'événement HTML