wx.openDocument-新开页面打开文档

wx.openDocument(OBJECT)

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


OBJECT参数说明:

参数说明必填说明最低版本
filePathString文件路径,可通过 downFile 获得
fileTypeString文件类型,指定文件类型打开文件,有效值 doc, xls, ppt, pdf, docx, xlsx, pptx1.4.0
successFunction接口调用成功的回调函数
failFunction接口调用失败的回调函数
completeFunction接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

wx.downloadFile({
    url: 'http://my.mcto.com.cn/images/a.docx',
    success: function (res) {
        var filePath = res.tempFilePath
        console.log(filePath)
        wx.openDocument({
            filePath: filePath,
            success: function (res) {
                console.log('打开文档成功')
            },
            fail:function(){
                console.log('出错了!')
            }
        })
    },
    fail:function(){
        console.log('error!')
    }
})

此文件直接会打开