1

Possible Duplicate:
javascript detect browser close tab/close browser

I have a java script countdown timer on my page and i want to trigger an alert message if user tries to close the window or a tab.

Community
  • 1
  • 1
  • 2
    [`window.onbeforeunload`](https://developer.mozilla.org/en-US/docs/DOM/window.onbeforeunload) – Adi Aug 28 '12 at 11:23

2 Answers2

2

https://developer.mozilla.org/en-US/docs/DOM/window.onbeforeunload

Update: this answer was provided by Adnan in comment few mins before me :)

sv_in
  • 13,929
  • 9
  • 34
  • 55
0

Use this event

window.onbeforeunload = function() {
   //your message goes here
}

By using jQuery

$(window).unbind("beforeunload");
$(window).bind("beforeunload", function (e) {
   //do your work here
});
Adi
  • 5,089
  • 6
  • 33
  • 47
RAKESH HOLKAR
  • 2,127
  • 5
  • 24
  • 42