Skip to content

Instantly share code, notes, and snippets.

@dmacompton
Created January 26, 2016 10:57
Show Gist options
  • Save dmacompton/a1cfe727a791911f2331 to your computer and use it in GitHub Desktop.
Save dmacompton/a1cfe727a791911f2331 to your computer and use it in GitHub Desktop.
Close Window
jQuery(document).ready(function(){
var changed='no';
$('input[type="text"]').change(function() {
changed='yes';
})
$(window).on('beforeunload', function() {
if (changed == 'yes'){
return "Были внесены изменения, которые НЕ БЫЛИ сохранены";
}
});
$('button[type="submit"]').click(function() {
$(window).off('beforeunload');
});
})
// Скрипт работает с Кверри, и при любом изменении любого инпута не даст просто так уйти со страницы или обновить страницу, если только не нажата кнопка СОХРАНИТЬ изменения (у меня в скрипте это Баттон (сабмитт) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment