Skip to content

Instantly share code, notes, and snippets.

@jsolid
Created September 17, 2012 04:46
Show Gist options
  • Save jsolid/3735617 to your computer and use it in GitHub Desktop.
Save jsolid/3735617 to your computer and use it in GitHub Desktop.
Display confirmation dialog before exiting/refreshing current page
var processDialog = new YAHOO.widget.Dialog('procDialog', {
width: '400px',
height: '350px',
underlay: 'shadow',
visible: false,
modal: true,
});
window.onbeforeunload = (function() {
if ( processDialog.cfg.getProperty('visible') &&
YAHOO.util.Dom.inDocument('actionMode') &&
YAHOO.util.Dom.get('processForm').elements['actionMode'].value != 'view' )
{
return 'If you leave now, data you have entered may not be saved.';
}
});
var isDataChanged = true;
window.onbeforeunload = (function() {
if(isDataChanged) {
//For IE only, Firefox and Chrome browsers have their own message to display
return 'If you leave now, data you have entered may not be saved.';
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment