onbeforeunload thuộc tính sự kiện kích hoạt khi tài liệu sẵn sàng được tải xuống.
Ví dụ
Bạn có thể thử chạy mã sau để triển khai onbeforeunload thuộc tính -
<!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>