Click here to Skip to main content
15,910,878 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
how to update database table when browser close.
Posted

There is simply no way to do this with surety.

When (and how) the browser closes is not in your control.
The browser could close because of a system crash - and even if you had code that would run when your browser closes, it would not execute.
 
Share this answer
 
 
Share this answer
 
see this example:-
XML
<script type="text/javascript">
     function unload()
    {
        if (document.getElementById('HdnisSave').value =='0')
        {
            event.returnValue = "UNSAVED DATA WILL BE LOST!!";
        }
    }
</script>
<body  onbeforeunload="unload()" >
<asp:HiddenField ID="HdnisSave" runat="server" Value="0" />


when your browser close than this js will inform you that your browser is closed and your data will be unsaved and give you some option like leave this or stay this page.
i hope it will help you.
when you save data than set hidden field value =1.
 
Share this answer
 
v2
Dear Friend,

If you are closing your window manually then before calling the function you can call another function or use ajax and update the data then call your function.
 
Share this answer
 
$(window).unload( function () {
alert("Bye now!");
//call server function using JQuery ajax
});
 
Share this answer
 

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