onunhandledrejection 特性为 WindowEventHandlers 混合 EventHandler 为处理 unhandledrejection events. These events are raised for unhandled Promise rejections.

句法

window.onunhandledrejection = function;
					

function EventHandler or function to call when unhandledrejection events are received by the window. The event handler receives as an input parameter as a PromiseRejectionEvent .

范例

This example simply logs unhandled rejections' reason values to the console.

window.onunhandledrejection = function(e) {
  console.log(e.reason);
}
					

规范

规范 状态 注释
HTML 实时标准
The definition of 'onunhandledrejection' in that specification.
实时标准 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
onunhandledrejection Chrome 49 Edge ≤79 Firefox 69
69
68 Disabled
Disabled From version 68: this feature is behind the dom.promise_rejection_events.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
部分支持 55 Disabled
This event handler was added in Firefox 55 but was disabled since it wasn't fully implemented. It was fully implemented in Firefox 68 and enabled by default in Firefox 69.
Disabled ). To change preferences in Firefox, visit about:config.
IE No Opera 36 Safari 11 WebView Android 49 Chrome Android 49 Firefox Android 68 Disabled
68 Disabled
Disabled From version 68: this feature is behind the dom.promise_rejection_events.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
部分支持 55 Disabled
This event handler was added in Firefox 55 but was disabled since it wasn't fully implemented. It was fully implemented in Firefox 68 but not enabled by default.
Disabled ). To change preferences in Firefox, visit about:config.
Opera Android No Safari iOS 11.3 Samsung Internet Android 5.0

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

用户必须明确启用此特征。

用户必须明确启用此特征。

元数据

  • 最后修改: