直接上干货
function previewPdf(fileBase64){
let fileBlob = this.base64ToBlobsdf(fileBase64,'application/pdf');
let basePdfUrl = window.URL.createObjectURL(fileBlob);
sessionStorage.setItem('basePdfUrl', basePdfUrl);
location.href = "lookPdf.html";
let newWindow = window.open("");
newWindow.document.write("<iframe width='100%' height='100%' src='"+href+"'></iframe>");
};
function base64ToBlobsdf(fileBase64,fileType){
let raw = window.atob(fileBase64);
let rawLength = raw.length;
let uint8Array = new Uint8Array(rawLength);
while (rawLength--){
uint8Array[rawLength] = raw.charCodeAt(rawLength);
}
return new Blob([uint8Array],{type: fileType});
};`
注意:Window。open()方法无法在微信内置浏览器里面打开,下载功能也无法在微信内置浏览器下载,原因大家都懂,此方法只支持浏览器端使用,微信内置浏览器下载请转到外部浏览器下载