how can i prevent onbeforeunload from firing when a certain condition is met?

前端 未结 5 1373
眼角桃花
眼角桃花 2020-12-11 16:46

i have a page on which i want to confirm if the user wants to leave. i have to confirm only when a certain condition is met so i wrote code like this

var bac         


        
5条回答
  •  -上瘾入骨i
    2020-12-11 17:12

    Condition for back-end

    var confirmExist = function (e) {
        return true;
    }
    window.onbeforeunload = confirmExist;
    http get, post request
    .then(function(r)) {
        window.onbeforeunload = null;
    }
    

提交回复
热议问题