Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii,


I am using this script ..
JavaScript
function SaveOrCancel() {
           document.getElementById('<%=hdnBack.ClientID %>').value = "";

           if (confirm("If you leave this screen you may lose any unsaved data") == true) {
               document.getElementById('<%=hdnBack.ClientID %>').value = "SAVE";
               return true;
           }
           else {
               document.getElementById('<%=hdnBack.ClientID %>').value = "BACK";
               return true;
           }
       }

this was i was using only for back button .. now what i want to do is if user try to leave that page ,.,, say if he click some other link of my application .. or he press back of browser .. he should be worn to save the chganges ... how can i do that ...

if he click save of that warning box my call should send to save button which will perform all the necessary action if he click cancel he simply redirect to whrereve he want to redirect
Posted

Try:
JavaScript
window.onbeforeunload = SaveOrCancel;
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 11-Oct-13 22:54pm    
5ed.
—SA
Thomas Daniels 12-Oct-13 9:47am    
Thank you!
Please check here Confirm before leaving page[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 11-Oct-13 22:54pm    
5ed.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900