运行 ❯
获取您的
自有
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>HTML DOM Events</h1> <h2>The beforeprint Event</h2> <p>Use the addEventListener() method to attach a "beforeprint" event to the window object.</p> <h3>Print this document!</h3> <p><b>Tip</b>: The keyboard shortcut Ctrl+P prints a page.</p> <script> window.addEventListener("beforeprint", myFunction); function myFunction() { alert("You are about to print this document!"); } </script> </body> </html>