jQuery/Javascript to detect OS without a plugin?

后端 未结 7 619
余生分开走
余生分开走 2020-11-27 16:40

I am looking for a way to detect the OS for a downloads page using jQuery or Javascript to recommend specific files for Mac vs Windows. I was hoping to do it without adding

7条回答
  •  自闭症患者
    2020-11-27 16:55

    You can use this function inside document ready function. Add the code inside function for your event.

    function checkOperatingSystem()
    {
        var  userAgent = navigator.userAgent || navigator.vendor || window.opera;
    
        //Check mobile device is Android
        if (/android/i.test(userAgent)) {
            //Add your Code here
        }
    
        //Check mobile device is IOS
        if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
            //Add your Code here
        }
    
        //Check device os is Windows (For Laptop and PC)
        if (navigator.appVersion.indexOf("Win")!=-1)
        {
            //Add your Code here
        }
    
        //Check device os is MAC (For Laptop and PC)
        if (navigator.appVersion.indexOf("Mac")!=-1)
        {
            //Add your Code here
        }  
    }
    

提交回复
热议问题