注册

wx.opendocument微信小程序新开页面打开文档怎么做

2020-12-07
导读:wx.openDocument(OBJECT) 新开页面打开文档,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx OBJECT参数说明: 参数 说明 必填 说明 最低版本 filePath String 是 文件路径,可...

wx.openDocument(OBJECT)


新开页面打开文档,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx

 

OBJECT参数说明:

参数 说明 必填 说明 最低版本
filePath String 文件路径,可通过 downFile 获得  
fileType String 文件类型,指定文件类型打开文件,有效值 doc, xls, ppt, pdf, docx, xlsx, pptx 1.4.0
success Function 接口调用成功的回调函数  
fail Function 接口调用失败的回调函数  
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)  

示例代码

wx.downloadFile({  url: 'http://example.com/somefile.pdf',
  success: function (res) {
    var filePath = res.tempFilePath 
    wx.openDocument({
      filePath: filePath,
      success: function (res) {
        console.log('打开文档成功')
      }
    })
  }
})
更多微信小程序开发教程,可以关注hi小程序。
重磅推荐:小程序开店目录

第一部分:小商店是什么

第二部分:如何开通一个小商店

第三部分:如何登录小商店

第四部分:开店任务常见问题

第五部分:小商店可以卖什么

第六部分:HiShop小程序特色功能

第七部分:小程序直播

第八部分:小程序收货/物流

第九部分:小程序怎么结算

第十部分:小程序客服

第十一部分:电商创业

第十二部分:小程序游戏开发