pdf.js加载网络地址跨域问题
使用pdf.js时,当有跨域的问题时,会加载失败,错误信息为file origin does not match viewer’s
看有有博主说直接注释掉web/viewer.js中如下代码就可以成功展示。
if (origin !== viewerOrigin && protocol !== 'blob:') {
throw new Error('file origin does not match viewer\'s');
}
我使用的版本是:pdfjs-2.7.570-es5-dist 适配老式浏览器
根据根据关键字origin搜到了如下代码,在3304行
// if (origin !== viewerOrigin && protocol !== "blob:") {
// throw new Error("file origin does not match viewer's");
// }
将这段代码注释掉以后,PDF文件预览成功。