window.addEventListener('beforeunload' function (event) {
  var confirmationMessage = '입력 내용이 모두 사라집니다.';
  event.returnValue = confirmationMessage;
 
  return confirmationMessage;
});
beforeunload 이벤트는 Mobile Safari에서는 지원하지 않습니다.
<!DOCTYPE html>
<html>
<body onbeforeunload="return myFunction()">

<p>Reload this page, or click on the link below to invoke the onbeforeunload event.</p>

<a href="https://www.w3schools.com">Click here to go to w3schools.com</a>
    
<script>
function myFunction() {
  return "Write something clever here...";
}
</script>

</body>
</html>
<!DOCTYPE html>
<html>
<body onbeforeunload="return myFunction()">

<p>This example demonstrates how to assign an "onbeforeunload" event to a body element.</p>

<p>Close this window, press F5 or click on the link below to invoke the onbeforeunload event.</p>

<a href="https://www.w3schools.com">Click here to go to w3schools.com</a>
    
<script>
function myFunction() {
  return "Write something clever here...";
}
</script>

</body>
</html>
<!DOCTYPE html>
<html>
<body>

<p>This example uses the HTML DOM to assign an "onbeforeunload" event to the window object.</p>

<p>Close this window, press F5 or click on the link below to invoke the onbeforeunload event.</p>

<a href="https://www.w3schools.com">Click here to go to w3schools.com</a>

<script>
window.onbeforeunload = function(event) {
  event.returnValue = "Write something clever here..";
};
</script>

</body>
</html>
<!DOCTYPE html>
<html>
<body>

<p>This example uses the addEventListener() method to attach a "beforeunload" event to the window object.</p>

<p>Close this window, press F5 or click on the link below to invoke the beforeunload event.</p>

<a href="https://www.w3schools.com">Click here to go to w3schools.com</a>

<script>
window.addEventListener("beforeunload", function(event) {
  event.returnValue = "Write something clever here..";
});
</script>

</body>
</html>

'☆Develpoer > ☆ WEB' 카테고리의 다른 글

autocomplete 속성 작성  (0) 2019.07.05
onbeforeunload Event  (0) 2019.07.04
[html] autocapitalize 속성  (0) 2019.07.03
카카오링크 미리보기 Cache 삭제하기  (0) 2017.11.20
iframe 스크롤 히든  (0) 2017.07.04
youtube v3 search  (0) 2017.06.17

+ Recent posts