English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The beforeprint event is triggered when the associated document is about to be printed or previewed for printing.
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 ‹/›
IEFirefoxOperaChromeSafari
Actuellement, seuls les navigateurs Internet Explorer et Firefox prennent en charge l'attribut d'événement onbeforeprint.
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
L'attribut onbeforeprint est un attribut HTML5Nouvel attribut.
<element onbeforeprint="script">
Valeur | Description |
---|---|
script | Script exécuté dans onafterprint. |