[removed] in Chrome: what is the most recent fix?

后端 未结 4 1659
伪装坚强ぢ
伪装坚强ぢ 2020-11-29 06:05

Obviously, window.onbeforeunload has encountered its fair share of problems with Chrome as I\'ve seen from all the problems I\'ve encountered. What\'s the most recent work a

4条回答
  •  误落风尘
    2020-11-29 06:19

    As of 69.0.3497.92, Chrome has not met the standard. However, there is a bug report filed, and a review is in progress.

    • Chrome requires returnValue to be set by reference to the event object, not the value returned by the handler.
    • The standard states that prompting can be controlled by canceling the event or setting the return value to a non-null value.
    • The standard states that authors should use Event.preventDefault() instead of returnValue.
    • The standard states that the message shown to the user is not customizable.

    window.addEventListener('beforeunload', function (e) {
        // Cancel the event as stated by the standard.
        e.preventDefault();
        // Chrome requires returnValue to be set.
        e.returnValue = '';
    });
        
    window.location = 'about:blank';

提交回复
热议问题