Skip to content

Instantly share code, notes, and snippets.

@ltackett
Created September 5, 2009 18:24
Show Gist options
  • Save ltackett/181473 to your computer and use it in GitHub Desktop.
Save ltackett/181473 to your computer and use it in GitHub Desktop.
var needToConfirm = false;
$('#experience textarea#experience_body, #new-discussion textarea#discussion_posts_attributes_0_text').bind('keypress', function(){
$('body').css('background-color', '#f00')
var needToConfirm = true;
});
$('input[type="submit"]').bind('click', function(){
$('body').css('background-color', '#fff')
var needToConfirm = false;
});
window.onbeforeunload = confirmExit;
function confirmExit(){
if (needToConfirm == true){
return "You haven't submitted your changes, and it looks \n" +
"like you're trying to browse away from this page. \n" +
"If you leave this page, your current changes will be lost.";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment