过时
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.

FileSystemEntry 接口方法 toURL () creates and returns a string containing a URL which can be used to identify the file system entry. This is done by exposing a new URL scheme— filesystem: —that can be used as the value of src and href 属性。

句法

FileSystemEntry.toURL([mimeType]);
					

参数

mimeType 可选

An optional string specifying the MIME type to use when interpreting the file. This can be used to help deal with files whose types aren't recognized automatically by the user agent. If this parameter is omitted, the user agent uses its standard algorithms to identify the file.

返回值

A DOMString containing a URL that can then be used as a document reference in HTML content, or an empty string if the URL can't be generated (such as if the file system implementation doesn't support toURL() ).

范例

If you have a FileSystemFileEntry corresponding to an image file in a file system available to your Web site or app, you can call toURL() to get its URL for use in HTML. If your site is located at http://my-awesome-website.woot , and you have a temporary file system that contains an image file named awesomesauce.jpg , the URL returned by toURL() might be (depending on the browser's implementation) something like "filesystem:http://my-awesome-website.woot/temporary/awesomesauce.jpg" .

Code that makes use of this might look like this:

let img = document.createElement("img");
img.src = imageFileEntry.toURL();
document.body.appendChild(img);
					

Assuming the scenario mentioned before the code, the result would be HTML that looks like this being appended to the end of the document:

<img src="filesystem:http://my-awesome-website.woot/temporary/awesomesauce.jpg">
					

浏览器兼容性

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
toURL 弃用 非标 Chrome 8 Edge 79 Firefox No IE No Opera No Safari No WebView Android ≤37 Chrome Android 18 Firefox Android No Opera Android No Safari iOS No Samsung Internet Android Yes

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

非标。预期跨浏览器支持较差。

非标。预期跨浏览器支持较差。

弃用。不要用于新网站。

弃用。不要用于新网站。

另请参阅

元数据

  • 最后修改: