I have to call a webservice using AJAX before browser gets closed. So to get the browser close event I am using the following javascript code
window.onbeforeunload = function(e) {
alert("Browser close event test");
e = e || window.event;
e.preventDefault = true;
e.cancelBubble = true;
e.returnValue = 'test';
//write your code here
}
Somehow it is only working in IE and not in Chrome and Firefox. Don't know why? You can check this fiddle in different browser https://jsfiddle.net/yFuPr/2149/
I have referred this post Crossbrowser onbeforeunload?
but for him it is not even working in IE. I have other problem, the code is only working in IE.