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
Imported scripts were not served with a valid JavaScript MIME type (i.e. 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.
实时标准

浏览器兼容性

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
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

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

另请参阅

元数据

  • 最后修改: