Created
January 26, 2016 10:57
-
-
Save dmacompton/a1cfe727a791911f2331 to your computer and use it in GitHub Desktop.
Close Window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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