Prevent Form Data Loss with jQuery

Dummy proof your app and ensure your data is saved, always!

Prompt a user to confirm, before they unload your page. I recently used this internally so as to prevent myself from leaving a page I'm editing in my CMS. It works wonders, use it if you please.

The Javascript:

            var submitted = false;
            $( "form" ).submit(function() {
                submitted = true;
            $(window).bind('beforeunload', function(){
                if (!submitted)
                return 'Are you sure you want to leave?';

perm_identityAli Jaffar


visibility958 reads


Did you enjoy this post?