0

Ask a question, and while editing the body of your question, click on some link on the page. StackOverflow's script knows that you are not finished yet, and warns you about loosing your unsaved data. However, it's confirmation box is not a jQuery plugin, or anything like that. It seems that its confirmation box is browser-specific box, something like JavaScript's confirm box. To prove it, simply check it in many browsers and you see different UI styles.

How they've done it? Which JavaScript command?

Saeed Neamati
  • 35,341
  • 41
  • 136
  • 188
  • 1
    possible duplicate of [Alerts when navigating away from a web page](http://stackoverflow.com/questions/1289234/alerts-when-navigating-away-from-a-web-page) – James Hill Nov 14 '11 at 13:33

3 Answers3

2

The onbeforeunload Javascript event is what you're looking for.

kapa
  • 77,694
  • 21
  • 158
  • 175
  • His question is a duplicate, I will remove my answer when this question is closed. – kapa Nov 14 '11 at 13:42
  • @Martin I already added the short answer when James marked it as a duplicate. So I did not write the longer version, as I normally do. – kapa Nov 14 '11 at 14:03
1

Trying setting a global flag to know when the page is "editing" and then use the onbeforeunload event

window.onbeforeunload = function(){ return globalEditingFlag ? 'You are editing': null }
Martin Borthiry
  • 5,256
  • 10
  • 42
  • 59
0

Look at this : http://www.w3schools.com/js/js_popup.asp

The section about the confirm box

GregM
  • 2,634
  • 3
  • 22
  • 37