I want to update a database(Sqlserver 2008) on browser close.
I have a table in which i have value 0, I want that 0 should be updated to 1 whenever user closes the browser. How can i do this?.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Kunal VaishyaRank #990 · 2K reputationPosted Jun 30, 2012, 12:27 AM EDT
this
"text/javascript" language="javascript"> window.onbeforeunload = function(event) { var msg = 'Are you sure you want to leave?'; if (((window.event.clientX || event.clientX) 0) || ((window.event.clientY || event.clientY)0)) // close button { event=window.event; event.returnValue = msg; return msg; } if ((window.event.clientX 0) || (window.event.clientY0)) // close button { event=window.event; event.returnValue = msg; return msg; } else if (window.event.altKey == true || window.event.ctrlKey == true) // ALT + F4 { event=window.event; event.returnValue = msg; return msg; } else // for all other unload events { } } script>Gohil JayendrasinhRank #490 · 5K reputationPosted Jun 30, 2012, 3:09 AM EDT
try it it's working
var preventUnloadPrompt;
var messageBeforeUnload = "my message here - Are you sure you want to leave this page?";
$('a').live('click', function () { preventUnloadPrompt = true; });
$('form').live('submit', function () { preventUnloadPrompt = true; });
$(window).bind("beforeunload", function (e) {
var rval;
if (preventUnloadPrompt) {
return;
} else {
//location.replace(redirectAfterPrompt);
return messageBeforeUnload;
}
return rval;
})
call ajax method and update your records.