How do I block the [removed]('beforeUnload') event for tag?

前端 未结 2 1736
死守一世寂寞
死守一世寂寞 2020-12-10 18:25

In my project I need to get the user confirmation alert , when the user want to close the window/tab using X button.

But the window.on(\'before

相关标签:
2条回答
  • 2020-12-10 18:39
    $(document).ready(function () {
        $('#navigate').on('mouseenter', stopNavigate)
            .on('mouseout', function () {
            $(window).on('beforeunload', windowBeforeUnload);
        });
    
    });
    
    function stopNavigate(event) {
        $(window).off('beforeunload');
    }
    
    function windowBeforeUnload() {
        return 'Are you sure you want to leave?';
    }
    
    $(window).on('beforeunload', windowBeforeUnload);
    

    DEMO

    0 讨论(0)
  • 2020-12-10 18:48

    Try this -

    $("a").mousedown(function() {
        $(window).unbind();
    });
    
    0 讨论(0)
提交回复
热议问题