In my program, if a user tries to leave a page, he'll receive a dialog box asking if he is sure he wants to leave.
How should I implement the 'cancel' option if the user chooses not to leave the page?
Source javascript code:
$(window).unload(function(){
var c= confirm ("Are you sure?");
if (c){
alert("Thanks. Good luck!");
}
else{
????
}
});
In my program, if a user tries to leave a page, he'll receive a dialog box asking if he is sure he wants to leave.
How should I implement the 'cancel' option if the user chooses not to leave the page?
Source javascript code:
$(window).unload(function(){
var c= confirm ("Are you sure?");
if (c){
alert("Thanks. Good luck!");
}
else{
????
}
});
Share
Improve this question
edited Aug 21, 2019 at 8:11
Brian Tompsett - 汤莱恩
5,88372 gold badges61 silver badges133 bronze badges
asked Mar 5, 2012 at 9:56
tatiana_ctatiana_c
9587 gold badges16 silver badges31 bronze badges
2
- 12 ONLY prompt the user if there are any kind of unsaved changes etc. NEVER EVER thank them with another alert dialog etc when they leave, it's the worst possible UX case. – zatatatata Commented Mar 5, 2012 at 9:58
- Thanks, I am agree. It is a very good advice when I think about it now. – tatiana_c Commented Mar 5, 2012 at 10:12
2 Answers
Reset to default 17window.onbeforeunload = function() {
return 'You have unsaved changes!';
}
many question about this in stackoverflow How can I override the OnBeforeUnload dialog and replace it with my own?
JavaScript + onbeforeunload
jQuery(window).on('beforeunload',function(){
var value = navigateAway(isDirty);
if(value=="changed")`enter code here`
{
if(jQuery("#saveCheck").val()=="false")
{
return "<?php echo JText::_('OVR_WANT_TO_LEAVE');?>";
}
}
});