문서가 로드되기 전에 이벤트를 트리거하려면 onbeforeunload를 사용하세요. 이벤트.
예시
다음 코드를 실행하여 JavaScript에서 onbeforeunload 이벤트를 구현하는 방법을 배울 수 있습니다.
<!DOCTYPE html>
<html>
<body onbeforeunload="return myFunction()">
<a href="https://www.qries.com">Click to open Qries</a>
<script>
function myFunction() {
return "Working with onbeforeunload event";
}
</script>
</body>
</html>