Sự kiện onbeforeunload kích hoạt trước khi tài liệu bị unload. Thường dùng để cảnh báo người dùng có thay đổi chưa lưu.
Ví dụ
<!DOCTYPE html>
<html>
<body onbeforeunload="return myFunction()">
<a href="https://www.qries.com">Click để mở Qries</a>
<script>
function myFunction() {
return "Đang làm việc với sự kiện onbeforeunload";
}
</script>
</body>
</html>