如何在保存数据之前显示离开页面的警报?仅使用javascript。我不想要Windows警报消息。我需要正常的警报窗口

时间:2015-12-23 06:37:53

标签: javascript jquery

以下代码工作正常,但我想要javascript警报,而不是Windows警报。

unsaved = false;
            $(":input").change(function () { 
                unsaved = true;
            });

            $(document).on("submit", "form", function (event) {

                unsaved = false;
                $(window).off('unload');
            });           

            function unloadPage() {
                if (unsaved) { 
                    return "You have unsaved changes on this page. Do you want to leave page?";
                }
            }   
            window.onbeforeunload = unloadPage;

0 个答案:

没有答案