1. 如果是微信小程序,可以使用微信接口:downloadFile和openDocument
wx.downloadFile({
// 示例 url,实际不存在
url: 'test.com/testfile.pd…', success: function (res) {
const filePath = res.tempFilePath
wx.openDocument({
filePath: filePath,
success: function (res) {
console.log('打开文档成功')
} })
}
})
如果明确只有微信使用可以考虑,只是如果有浏览直接使用或钉钉之类不行,而且如果后面更换到浏览器或WEBAPP又要更换也挺麻烦的。
2.pfile的文件预览
最近新发现的,很简单一句话
window.open('www.pfile.com.cn/api/profile…);
目前使用了一段时间,没发现有什么缺点,强烈推荐!