close() 方法在 SharedWorkerGlobalScope interface discards any tasks queued in the SharedWorkerGlobalScope 's event loop, effectively closing this particular scope.

句法

self.close();
					

范例

If you want to close your worker instance from inside the worker itself, you can call the following:

close();
					

close() and self.close() are effectively equivalent — both represent close() being called from inside the worker's inner scope.

注意 : There is also a way to stop the worker from the main thread: the Worker.terminate 方法。

规范

规范 状态 注释
HTML 实时标准
The definition of 'close()' in that specification.
实时标准

浏览器兼容性

The compatibility table in 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
close Chrome No Edge No Firefox 54 IE No Opera No Safari ? WebView Android No Chrome Android No Firefox Android 54 Opera Android No Safari iOS ? Samsung Internet Android No

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

General note: In newer browser versions, close() is available on SharedWorkerGlobalScope and DedicatedWorkerGlobalScope . In older browser versions, it is available on WorkerGlobalScope . This change was made to stop close() being available on service workers, as it isn't supposed to be used there and always throws an exception when called (see bug 1336043 ).

另请参阅

DedicatedWorkerGlobalScope

元数据

  • 最后修改: