0

I have a page where I need to perform a task on unload but only when the page is closed. The problem I am having is that the unload also runs when refreshing (or postback) the page which will cause problems.

This is what I am using to test the event at the moment:

$( window ).unload(function() {
  alert( "Bye now!" );
});

I need to use a similar function but not when the page is refreshed or a postback has occurred.

connersz
  • 1,153
  • 3
  • 23
  • 64

1 Answers1

0

I suggest you to check window.onbeforeunload event to achieve your behavior. Refer this for reference.

Community
  • 1
  • 1
RGR
  • 1,521
  • 2
  • 22
  • 36
  • But Window.onbeforeunload also execute on page refresh or postback...Can you provide any code or link to avoid it on refresh/postback... – Rakesh_HBK Jan 27 '14 at 13:07