confirm() on [removed]

前端 未结 3 666
广开言路
广开言路 2020-12-01 22:11

I want to show a confirmation dialog if the user wants to leave the page with unsaved form data. What I have is:

window.onbeforeunload = function() {
    if          


        
3条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 22:38

    With jQuery, you can set the same handlers. The code may defer based on your version.

        function AnyFunction(e){ /**** your code *****/ };
    
        $(function () {
          $(window).bind('unload', function (e) { return AnyFunction(e); });
          $(window).bind('beforeunload', function (e) { return AnyFunction(e); });
        });
    

    You can also change the confirm or alert function using plugins as bootbox.

提交回复
热议问题