2009-02-05 54 views

Trả lời

12

Ví dụ:

<script type="text/javascript"> 
    var shouldConfirm = false; 
    window.onbeforeunload = function() { 
     if(shouldConfirm) { 
      return "You have made unsaved changes. Would you still like to leave this page?"; 
     } 
    } 
</script> 

<input id="FullName" type="text" /> 
<script type="text/javascript"> 
    document.getElementById('FullName').onchange = function() { 
     shouldConfirm = true; 
    } 
</script> 

Có một bài viết đầy đủ tại 4GuysFromRolla.com.

0

Đây là cách nó có thể được thực hiện nhưng điều này không phải lúc nào cũng đáng tin cậy:

<html> 
<head> 
<script type="text/javascript"> 
function leaving() 
{ 
    if(confirm("Would you like to save?")) 
    { 
     //Save info 
    } 
    else 
    { 
     //Don't save 
    } 
} 
</script> 
</head> 
<body onUnload="leaving()"> 
<!--Stuff--> 
</body> 
</html> 
Các vấn đề liên quan