• Dreamhost Banner Ad

How To Warn User Before Leaving Your Web Page With Unsaved Changes

Here’s a Jquery script I tested on the project I’m doing to warn user that their changes will not be saved once they navigated away from the page without clicking the submit button yet.

Just copy paste it on the footer of any page you want to have warnings on, inside the script tag.

var isSubmitting = false;

$(document).ready(function () {
isSubmitting = true;

$('form').data('initial-state', $('form').serialize());

$(window).on('beforeunload', function() {
if (!isSubmitting && $('form').serialize() != $('form').data('initial-state')){
return 'You have unsaved changes which will not be saved.'

Marhgil Macuha

Marhgil Macuha is a Computer Engineering graduate of Batangas State University. He is a professional network marketer in the Philippines, with business partners all over the world.

Facebook Comments

Leave a Reply