概述

AbstractWorker接口的onerror特性是一个事件句柄,在 Workererror事件触发并冒泡时执行。

语法

myWorker.onerror = function() { ... };

示例

下面的代码片段展示了通过 Worker() 创建 Worker 对象的过程, 以及设置onerror回调函数:

var myWorker = new Worker("worker.js");

myWorker.onerror = function() {
  console.log('There is an error with your worker!');
}

规范

Specification Status Comment
HTML Living Standard
AbstractWorker.onerror
Living Standard No change from Unknown.
Unknown
AbstractWorker.onerror
Unknown Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 4Edge Full support 12Firefox Full support 3.5IE Full support 10Opera Full support 10.6Safari Full support 4WebView Android Full support 4.4Chrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support 4Opera Android Full support 11.5Safari iOS Full support 5.1Samsung Internet Android Full support Yes

Legend

Full support  
Full support

试图加载跨域 Worker 的错误差异

早期浏览器会抛出 SecurityError,在规范变更后,则是  error 事件。具体见 Loading cross-origin worker now fires error event instead of throwing; worker in sandboxed iframe no longer allowed.

 

另请参阅

文档标签和贡献者

此页面的贡献者: Jack.Works, liuzeyafzy
最后编辑者: Jack.Works,