2009-02-05 20 views

Odpowiedz

12

Przykład:

<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> 

Jest pełny artykuł na 4GuysFromRolla.com.

0

ten sposób można to zrobić, ale to nie zawsze jest niezawodny:

<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> 
Powiązane problemy