Obsolete
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
The close()
method of the WorkerGlobalScope
interface discards any tasks queued in the WorkerGlobalScope
's event loop, effectively closing this particular scope.
Syntax
self.close();
Example
If you wanted to close your worker instance from inside the worker itself, you could call the following:
close();
close()
and self.close()
are effectively equivalent — both represent close()
being called from inside the worker's inner scope.
Note: there is also a way to stop the worker from the main thread: the Worker.terminate
method.
Browser compatibility
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.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
close | Chrome Full support 4 | Edge Full support 12 | Firefox Full support 3.5 | IE Full support Yes | Opera Full support 11.5 | Safari Full support 4 | WebView Android Full support 37 | Chrome Android Full support Yes | Firefox Android Full support 4 | Opera Android ? | Safari iOS ? | Samsung Internet Android Full support Yes |
close() moved to DedicatedWorkerGlobalScope and SharedWorkerGlobalScope | Chrome Full support 52 | Edge Full support ≤79 | Firefox Full support 54 | IE ? | Opera ? | Safari ? | WebView Android Full support 52 | Chrome Android Full support 52 | Firefox Android Full support 54 | Opera Android ? | Safari iOS ? | Samsung Internet Android Full support 6.0 |
Legend
- Full support
- Full support
- Compatibility unknown
- Compatibility unknown
- Non-standard. Expect poor cross-browser support.
- Non-standard. Expect poor cross-browser support.
- Deprecated. Not for use in new websites.
- Deprecated. Not for use in new websites.