Mozilla firefox not working with [removed]

前端 未结 4 650
清酒与你
清酒与你 2020-11-30 11:35

I\'m using window.onbeforeunload to display a message to the user on windows close, the function works well with Chrome and IE but it doesn\'t work with Firefox

4条回答
  •  悲&欢浪女
    2020-11-30 12:13

    I looked for a Firefox onbeforeunload solution over 2 days and with no luck, so I worked hard on this, and did it with a little trick.

    In my trick, the user needs to click on the browser window at least once. If the user clicks on the window and then clicks on the back button, refreshes the page, or tries to exit the page, onbeforeunload events will fire,

    $(window).on('beforeunload', function () {
        return "Are you sure you want to exit this page?";
    });
    $(window).one('click',function(){
        alert('hi');
        $('.javavoid').trigger('click');
    });
    .hide{display:none;}
    
    
        asdf
        

    Welcome, click anywhere then click on back button or refresh page

提交回复
热议问题