Blob 接口的 slice() method creates and returns a new Blob object which contains data from a subset of the blob on which it's called.

句法

var newBlob = blob.slice(start, end, contentType);
					

参数

start 可选
An index into the Blob indicating the first byte to include in the new Blob . If you specify a negative value, it's treated as an offset from the end of the Blob toward the beginning. For example, -10 would be the 10th from last byte in the Blob . The default value is 0. If you specify a value for start that is larger than the size of the source Blob , the returned Blob has size 0 and contains no data.
end 可选
An index into the Blob indicating the first byte that will *not* be included in the new Blob (i.e. the byte exactly at this index is not included). If you specify a negative value, it's treated as an offset from the end of the Blob toward the beginning. For example, -10 would be the 10th from last byte in the Blob 。默认值为 size .
contentType 可选
The content type to assign to the new Blob ; this will be the value of its type property. The default value is an empty string.

返回值

新的 Blob object containing the specified subset of the data contained within the blob on which this method was called. The original blob is not altered.

规范

规范 状态 注释
文件 API
The definition of 'Blob.slice()' 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
slice() Chrome 21
21
不支持 5 — 25 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge 12 Firefox 13
13
Prior to Firefox 12, there was a bug that affected the behavior of Blob.slice() ; it did not work for start and end positions outside the range of signed 64-bit values; it has now been fixed to support unsigned 64-bit values.
不支持 5 — 13 Prefixed
Prefixed Implemented with the vendor prefix: moz
IE 10 Opera 12 Safari 5.1 Prefixed
5.1 Prefixed
Prefixed Implemented with the vendor prefix: webkit
WebView Android Yes Chrome Android 25
25
不支持 18 — 25 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android 14 Opera Android Yes Safari iOS Yes Samsung Internet Android 1.5
1.5
不支持 1.0 — 1.5 Prefixed
Prefixed Implemented with the vendor prefix: webkit

图例

完整支持

完整支持

见实现注意事项。

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

另请参阅

元数据

  • 最后修改:
  1. Blob
  2. 构造函数
    1. Blob()
  3. 特性
    1. size
    2. type
  4. 方法
    1. arrayBuffer()
    2. slice()
    3. stream()
    4. text()
  5. 文件 API 相关页面
    1. File
    2. FileList
    3. FileReader
    4. FileReaderSync

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1