importScripts()
方法在
WorkerGlobalScope
interface synchronously imports one or more scripts into the worker's scope.
self.importScripts('foo.js');
self.importScripts('foo.js', 'bar.js', ...);
A comma-separated list of
DOMString
objects representing the scripts to be imported. These paths are relative to
html document base URL
.
None.
NetworkError
text/javascript
).
If you had some functionality written in a separate script called
foo.js
that you wanted to use inside worker.js, you could import it using the following line:
importScripts('foo.js');
importScripts()
and
self.importScripts()
are effectively equivalent — both represent
importScripts()
being called from inside the worker's inner scope.
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'importScripts()' in that specification. |
实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
importScripts
|
Chrome 4 | Edge 12 | Firefox 4 | IE 10 | Opera 10.6 | Safari 4 | WebView Android ≤37 | Chrome Android 18 | Firefox Android 4 | Opera Android 11 | Safari iOS 3.2 | Samsung Internet Android 1.0 |
Strict MIME type checks for
importScripts()
|
Chrome 71 | Edge ≤79 | Firefox 67 | IE ? | Opera 58 | Safari No | WebView Android 71 | Chrome Android 71 | Firefox Android 67 | Opera Android 50 | Safari iOS No | Samsung Internet Android 10.0 |
完整支持
不支持
兼容性未知