方法
/*** 判断mac系统(含iphone手机) ***/
let isMac = /macintosh|mac os x/i.test(navigator.userAgent);
/*** 判断windows系统 ***/
let isWindows = /windows|win32/i.test(navigator.userAgent);
是否是移动端
let sUserAgent = navigator.userAgent.toLowerCase();
let isIpad = sUserAgent.match(/ipad/i) == "ipad";
let isIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
let isMidp = sUserAgent.match(/midp/i) == "midp";
let isUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
let isUc = sUserAgent.match(/ucweb/i) == "ucweb";
let isAndroid = sUserAgent.match(/android/i) == "android";
let isCE = sUserAgent.match(/windows ce/i) == "windows ce";
let isWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
let isMobile=isIpad || isIphoneOs || isMidp || isUc7 || isUc || isAndroid || isCE || isWM
export default isMobile
应用场景-通过浏览器window.open()方式的文件下载
对于无法被浏览器直接打开的文件(如zip,exe等),OS的safari浏览器会默认阻止window.open(url)弹框,从而无法下载。
(注:pdf这类可直接在浏览器打开的仍然可使用window.open())
需要做判断
import isMobile from '@/utils/isMobile'
downloadFile(url){
let isMac = /macintosh|mac os x/i.test(navigator.userAgent);
if(isMac&&!isMobile){
window.location.href=url
}else{
window.open(url)
}
}