I use the following code, which works fine in Internet Explorer, but doesn't work in Firefox.
When the user closes the browser, you must call the web method, which updates the bit field IsLogin=false in the database.
window.onbeforeunload = function (e) { var evt = window.event || e; var y = evt.clientY || evt.pageY; if (y < 0 || evt.clientX<0) { $.ajax({ type: "POST", url: "/Application/WebForm1.aspx/Update", async: false, data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { alert('Sucessfull Call'); } }); } }
source share