문제

Is there a way to cancel the javascript event onbeforeunload, and just have it execute a function and return to the page?

window.onbeforeunload = function(){
    //execute some logic
    return false;
}
도움이 되었습니까?

해결책

No. You cannot cancel this event. All you can do is have it return a string. That will make the browser ask the user if they want to leave.

Just imagine if you could block this event! You could make a site that the user could never close! Just imagine all the popups you could make. There's no way browsers are going to allow this.

다른 팁

No. You can't stop people leaving a page if they want to.

Yes. You can do this by making it null.

window.onbeforeunload = null;

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top