
There are two events on client side as given below.
1. window.onbeforeunload (calls on Browser/tab Close & Page Load)
2. window.onload (calls on Page Load)
On server Side
--------------- public JsonResult TestAjax( string IsRefresh)
{
JsonResult result = new JsonResult();
return result = Json("Called", JsonRequestBehavior.AllowGet);
}
On Client Side
---------------- <script type="text/javascript">
window.onbeforeunload = function (e) {
$.ajax({
type: 'GET',
async: false,
url: '/Home/TestAjax',
data: { IsRefresh: 'Close' }
});
};
window.onload = function (e) {
$.ajax({
type: 'GET',
async: false,
url: '/Home/TestAjax',
data: {IsRefresh:'Load'}
});
};
</script>
On Browser/Tab Close
----------------------- if user close the Browser/tab, then window.onbeforeunload will fire and IsRefresh value on server side will be "Close".
On Refresh/Reload/F5
------------------------ If user will refresh the page, first window.onbeforeunload will fire with IsRefresh value = "Close" and then window.onload will fire with IsRefresh value = "Load", so now you can determine at last that your page is refreshing.
Also refer:
http://stackoverflow.com/questions/6741397/is-there-a-way-to-detect-if-the-user-has-pressed-the-refresh-button-using-jquery Hope that helps
--
Thanks & Regards,
RNA Team
Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator