判断windows系统还是OS系统

方法

/*** 判断mac系统(含iphone手机) ***/
let isMac = /macintosh|mac os x/i.test(navigator.userAgent);

/*** 判断windows系统 ***/
let isWindows = /windows|win32/i.test(navigator.userAgent);

应用场景-通过浏览器window.open()方式的文件下载

对于无法被浏览器直接打开的文件(如zip,exe等),OS的safari浏览器会默认阻止window.open(url)弹框,从而无法下载。
(注:pdf这类可直接在浏览器打开的仍然可使用window.open())

需要做判断
downloadFile(url){
    let isMac = /macintosh|mac os x/i.test(navigator.userAgent);
    if(isMac){
        window.location.href=url
    }else{
        window.open(url)
    }
}
原文地址:https://www.cnblogs.com/huihuihero/p/15188318.html