เหตุการณ์ onpagehide จะทริกเกอร์ใน JavaScript เมื่อผู้ใช้ออกจากหน้าและตัดสินใจย้ายไปที่อื่น ตัวอย่างบางส่วน ได้แก่ การรีเฟรชอายุ การคลิกลิงก์ เป็นต้น
ตัวอย่าง
คุณสามารถลองใช้โค้ดต่อไปนี้เพื่อเรียนรู้วิธีใช้เหตุการณ์ onpagehide ใน JavaScript
<!DOCTYPE html> <html> <body onpagehide="newFunc()"> <p>Close the page and see what happens!</p> <script> function newFunc() { alert("Thank you!"); } </script> </body> </html>