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>
<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
Post a Comment