title: Taro.openDocument(option)
sidebar_label: openDocument
Opens a file in a new page.
Type
(option: Option) => Promise<CallbackResult>
Parameters
Option
| Property | Type | Required | Description |
|---|---|---|---|
| filePath | string |
Yes | File path, which can be obtained via downloadFile |
| fileType | "doc" | "docx" | "xls" | "xlsx" | "ppt" | "pptx" | "pdf" |
No | File type in which the file is opened |
| complete | (res: any) => void |
No | The callback function used when the API call completed (always executed whether the call succeeds or fails) |
| fail | (res: any) => void |
No | The callback function for a failed API call |
| success | (res: Result) => void |
No | The callback function for a successful API call |
fileType
Valid values of object.fileType
| Property | Description |
|---|---|
| doc | doc format |
| docx | docx format |
| xls | xls format |
| xlsx | xlsx format |
| ppt | ppt format |
| pptx | pptx format |
| pdf format |
Sample Code
Taro.downloadFile({url: 'https://example.com/somefile.pdf',success: function (res) {var filePath = res.tempFilePathTaro.openDocument({filePath: filePath,success: function (res) {console.log('File opened successfully')}})}})
API Support
| API | WeChat Mini-Program | H5 | React Native |
|---|---|---|---|
| Taro.openDocument | ✔️ |
