Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 智能手机操作系统的版本号';s_Javascript_Android_Ios_Regex_Blackberry - Fatal编程技术网

Javascript 智能手机操作系统的版本号';s

Javascript 智能手机操作系统的版本号';s,javascript,android,ios,regex,blackberry,Javascript,Android,Ios,Regex,Blackberry,可能重复: 是否有任何经得起未来考验的正则表达式可以从用户代理获取以下智能手机操作系统的版本号 Android (我发现了类似于:/Androids+([d.]+)/) iOS 黑莓 任何建议都将不胜感激 澄清:问题似乎是问如何在web应用程序中获得移动设备OS版本,可能是使用JS 更新: 在我被问这个问题吓了一跳之后,我想至少提供我想出的解决方案: supportedDevice: function() { var supportedDevice = false; var u

可能重复:

是否有任何经得起未来考验的正则表达式可以从用户代理获取以下智能手机操作系统的版本号

Android

(我发现了类似于:/Androids+([d.]+)/)

iOS

黑莓

任何建议都将不胜感激

澄清:问题似乎是问如何在web应用程序中获得移动设备OS版本,可能是使用JS

更新:

在我被问这个问题吓了一跳之后,我想至少提供我想出的解决方案:

supportedDevice: function() {
    var supportedDevice = false;
    var userAgent = window.navigator.userAgent;

    // check for supported Android device
    if ( /Android/.test(userAgent) ) {
        var a_index = Number(userAgent.indexOf('Android')) + 8;
        var a_version = +userAgent.substring(a_index, a_index+1);
        if ( a_version >= 3 ) {
            supportedDevice = true;
            console.log('Android device supported!')
        }

    }
    // check for iOS supported devices
    else if ( /iPhone/.test(userAgent) ) {
        var i_index = Number(userAgent.indexOf('iPhone OS')) + 10;
        var i_version = +userAgent.substring(i_index, i_index+1);
        if ( i_version >= 6 ) {
            supportedDevice = true;
            console.log('iPhone device supported!')
        }
    }
    // check for iOS supported devices
    else if ( /BlackBerry/.test(userAgent) ) {
        var b_index = Number(userAgent.indexOf('Version/')) + 8;
        var b_version = +userAgent.substring(b_index, b_index+1);
        if ( b_version >= 6 ) {
            supportedDevice = true;
            console.log('BB device supported!')
        }
    }
    return supportedDevice;
}

如果您需要在web应用程序中获取版本号,最好使用设备用户代理并解析出版本号。更可靠的方法是在中查找用户代理,以获得设备特征和相应的操作系统。第一种方法更简单


如果您使用的是应用程序,大多数操作系统SDK都会提供API来识别设备上运行的操作系统版本

您通常不会使用正则表达式来获取版本号;您可能会使用特定于平台的方法来获取该数字。您如何使用刚刚使用HTML5、CSS3和JavaScript等开放标准开发的移动web应用程序中的特定于平台的方法?请提供您从编程语言端看到的输入。例如:IOS 5.2.1等,他想解析移动浏览器发送的用户代理头。