0

I want to fire a function ( client side ) when the user is trying to leave the page only, by means if the user try to post back the page it shouldn't fire out, but only in condition that user is closing tab or closing window... at the time only the code will fire up.

I tried window.onbeforeunload unfortunately it generates in all conditions (User navigating - refresh - Post back - closing tab - etc...) ... But i need an event to fire function only when user is closing page and it would be great if i can also figure out when the user is changing URL too.

I'm using ASP.Net attaching JavaScript code to it for maintenance purpose.

Kero
  • 79
  • 2
  • 10
  • you can find a solution here : http://stackoverflow.com/questions/17975068/calling-js-functions-on-browser-tab-close . check if the page is navigating or refreshing or the tab is being closed and show the alert accordingly. – Md Ashaduzzaman Nov 24 '13 at 14:42
  • Yes, but in my case it will be for good use. I'm only detecting if user make some changes then when he is leaving I'm gonna tell him be-careful you forgot some changes happened ... so that i want to notify him about losing data ... and about link handling mostly i will not be using links and may be I'm using iframes, or user controls then `window.onbeforeunload` will fire in iframe case or user control button case. – Kero Nov 24 '13 at 14:59
  • I've posted an answer. Simply modified the solution that I previously referred to. – Md Ashaduzzaman Nov 24 '13 at 15:22

0 Answers0