Tuesday, October 31, 2006

Javascript code for Confirm leaving page (like editing blogspot.com )

If you are editting your blog at blogspot.com your browser would ask your confirmation if you'r not yet saved your modification.
Here's the javascript code
< script type="text/javaScript" >
var needToConfirm = true;
window.onbeforeunload = confirmExit;

function confirmExit() {
if (needToConfirm)
doyou = confirm('Are you sure you wish to leave this page?\n\nLeaving this page now will result in any data that you have already entered being lost.');

if (doyou == false)
return false;
}
</script>
a litle modification on this script will do better.
<script type="text/javaScript">
var needToConfirm = true;
window.onbeforeunload = confirmExit;

function confirmExit() {
if (needToConfirm)
doyou = false;

if (doyou == false)
return false;
}
</script>
too bad we cant customized the message.
The script will display this confirmation message "are you sure you want to navigate away from this page?
press ok to continue, or cancel to stay on the current page"
if anyone know how, please reply to this post