Question

How to show something similar to an alert like SO does here with javascript?

Was it helpful?

Solution

you'll need to do ajax polling for the "load new answers" alert that appears whilst you are writing an answer.

Here's a nice tutorial for ASP.NET using jQuery

For the alert when you attempt to navigate away from a page when you have started typing an answer/ editing a post, look at the onunload event. A confirm dialog is used as opposed to an alert

OTHER TIPS

Are we talking about SO warning you when you try to navigate away from a page with a partially filled in comment/answer ? Check out the onunload() method in Javascript. See here for an example.

add this script to the head portion of your page:

<script language="javascript">
  window.addEventListener('beforeunload', onUnload, false);
  function onUnload(e)
  {
    e.returnValue = "some Text";//this is your message
    e.preventDefault();
  }
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top