Skip to main content

Clear Session on browser/tab close using JQuery

Add below script to master page and replace Logon with your login page.
<script type="text/javascript">
var LoginPageName = "Logon";
var AttachClearSessionEvent = true; var IsFormSubmit = false;
$(window).submit(function () { AttachClearSessionEvent = false; IsFormSubmit = true; window.onbeforeunload = null; });
$(document).ready(function () {var myEvent = window.attachEvent || window.addEventListener;var chkevent = window.attachEvent ?
'onbeforeunload' : 'beforeunload'; /// make IE7, IE8 compitable
myEvent(chkevent, function (e) { // For >=IE7, Chrome, Firefox
try {if (AttachClearSessionEvent) {var caller = '(document).ready';var urlToDisposeSession = LoginPageName;
$.ajax({cache: false,type: "POST",url: urlToDisposeSession,data: JSON.stringify({ RandomString: caller }),contentType:
"application/json; charset=utf-8",dataType: "json",async: false,success: function (msg) {}});}
}catch (ex) { }
});});
$(window).on('mouseover', (function () {AttachClearSessionEvent = false;window.onbeforeunload = null;}));
function addEvent(obj, evt, fn) {if (obj.addEventListener) {obj.addEventListener(evt, fn, false);}else if (obj.attachEvent)
{obj.attachEvent("on" + evt, fn);}}
addEvent(window, "load", function (e) {
addEvent(document, "mouseout", function (e) {e = e ? e : window.event;var from = e.relatedTarget || e.toElement;
if (!from || from.nodeName == "HTML") {
var callOnMouseOut = true;
if (IsFormSubmit) { callOnMouseOut = false; } if (callOnMouseOut) { AttachClearSessionEvent = false; window.onbeforeunload =
ConfirmLeavemouseout;}}
});});
function ConfirmLeave() {
try {var Caller = 'Keyboard';var urlToDisposeSession = LoginPageName;
$.ajax({cache: false,type: "POST",url: urlToDisposeSession,data: JSON.stringify({ RandomString: Caller }),contentType:
"application/json; charset=utf-8",dataType: "json",async: false});
}catch (ex) { }}
function ConfirmLeavemouseout() {
try {var Caller = 'mouseout';var urlToDisposeSession = LoginPageName;
$.ajax({cache: false,type: "POST",url: urlToDisposeSession,data: JSON.stringify({ RandomString: Caller }),contentType:
"application/json; charset=utf-8",dataType: "json",async: false,success: function(msg) {}});
}catch (ex) { }}
var prevKey = "";
$(document).keydown(function (e) {if (e.key == "F5") {window.onbeforeunload = ConfirmLeave;}else if (e.key.toUpperCase() == "W"
&& prevKey == "CONTROL") {window.onbeforeunload = ConfirmLeave;}
else if (e.key.toUpperCase() == "R" && prevKey == "CONTROL") {window.onbeforeunload = ConfirmLeave;}else if
(e.key.toUpperCase() == "F4" && (prevKey == "ALT" || prevKey == "CONTROL")) {window.onbeforeunload = ConfirmLeave;}
prevKey = e.key.toUpperCase(); });
</script>

Comments

Popular posts from this blog

Visual Studio 2010 Error HRESULT E_FAIL has been returned from a call to a COM component.

I was using Visual Studio 2010.  I was debugging a web application and an exception happened and VS 2010 froze.  I ended the VS 2010 in the task manager and when I went back to developing, I found on every form for every ASP.net control I get:  Error Creating Control - Error HRESULT E_FAIL has been returned from a call to a COM component.  Also I am unable to edit  the form or add anything from the toolbox. Solution: This error comes because of Caching of Visual Studio Delete the Cache. You can delete the project cache at "Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplatesCache", then run "devenv /setup" to build the cache again to see if it helps.

Password Protected File Validation for(.doc/.docx/.xls/.xlsx/.pdf) file types

Password Protected File Validation for(.doc/.docx/.xls/.xlsx/.pdf) file types protected void btnUpload_Click( object sender, EventArgs e)         {             //Check if File Upload control has file or not             if (FileUpload1.HasFile)             {                 //Get Uploaded file bytes                 var bytes = FileUpload1.FileBytes;                 //Get Uploaded File Extension                 FileInfo objFileInfo = new FileInfo (FileUpload1.FileNam...

PDF Editor

http://www.pdfescape.com PDFescape is a free, online PDF reader, editor, form filler, & form designer. Free PDF Reader Free PDF Editor Free PDF Form Filler Free PDF Form Designer Free Webmaster Tools No Downloads No Watermarks A new way to open and edit PDF files online, PDFescape frees users from the typical software requirements for using the de facto document file format. Completely online, PDFescape requires no more than a modern internet browser and an active internet connection. Select any of the major features above to learn more.