Prompt confirm before Leaving edited html form

后端 未结 6 1383
被撕碎了的回忆
被撕碎了的回忆 2021-02-04 18:50

If user tries to leave unsaved edited form, a message box pop-up

\"This page is asking you to confirm that you want to leave - data you have entered may not be saved. Le

6条回答
  •  没有蜡笔的小新
    2021-02-04 18:58

    You can easily protect your form with jQuery with this simple unobtrusive code. Put in just before your closing tag.

    (function () {
        jQuery('form').one('change', function () {
            window.onbeforeunload = function () {
                return 'Form protection';
            };
        });
    })();
    

提交回复
热议问题