ก่อนโหลด แอตทริบิวต์ event' เริ่มทำงานเมื่อเอกสารพร้อมที่จะยกเลิกการโหลด
ตัวอย่าง
คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อใช้งาน onbeforeunload แอตทริบิวต์ −
<!DOCTYPE html>
<html>
<body onbeforeunload = "return display()">
<p>Close this window or press F5.</p>
<script>
function display() {
return "Wanna stay here or leave?";
}
</script>
</body>
</html>