- uni.openDocument(OBJECT)
uni.openDocument(OBJECT)
新开页面打开文档,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx。
平台差异说明
| 5+App | H5 | 微信小程序 | 支付宝小程序 | 百度小程序 | 头条小程序 |
|---|---|---|---|---|---|
| √ | x | √ | √ | √ | x |
OBJECT 参数说明:
| 参数名 | 类型 | 必填 | 说明 | 平台差异说明 |
|---|---|---|---|---|
| filePath | String | 是 | 文件路径,可通过 downFile 获得 | |
| fileType | String | 否 | 文件类型,指定文件类型打开文件,有效值 doc, xls, ppt, pdf, docx, xlsx, pptx | 微信小程序 |
| success | String | 否 | 接口调用成功的回调函数 | |
| fail | String | 否 | 接口调用失败的回调函数 | 微信小程序 |
| complete | String | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
示例代码:
uni.downloadFile({url: 'https://example.com/somefile.pdf',success: function (res) {var filePath = res.tempFilePath;uni.openDocument({filePath: filePath,success: function (res) {console.log('打开文档成功');}});}});
平台差异
| 平台 | 打开方式 |
|---|---|
| 小程序 | 在小程序的入口应用内打开 |
| 5+App iOS | 在当前应用内打开 |
| 5+App Android | 调用系统相关应用打开,无相关应用则不能打开 |
| H5 | 使用浏览器打开,当前浏览器不支持则不能打开 |
Tips
App端有更强大的plus.io API可用。https://www.html5plus.org/doc/zh_cn/io.html
发现错误?想参与编辑?在 GitHub 上编辑此页面!
