Saeed Neamati
Saeed Neamati

Reputation: 35832

How to show confirm box like StackOverflow's confirmation box?

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?

Upvotes: 0

Views: 256

Answers (3)

Martin Borthiry
Martin Borthiry

Reputation: 5326

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 }

Upvotes: 1

GregM
GregM

Reputation: 2654

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

The section about the confirm box

Upvotes: 0

kapa
kapa

Reputation: 78681

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

Upvotes: 2

Related Questions