JavaScriptでOSを判別するコード

方法1
var osPlatForm= navigator.platform.toLowerCase();
var agent = navigator.userAgent.toLowerCase();
var isIpod = hardwarePlatform.indexOf(“iPod") != -1;
var isIphone = hardwarePlatform.indexOf(“iPhone") != -1;
var isIpad = hardwarePlatform.indexOf(“iPad") != -1;
var isAndroid = agent.indexOf(“android") !=-1;
screen.height <= 320 || screen.width <= 320

方法2
function validataOS(){
if(navigator.userAgent.indexOf(“Window")>0){
return “Windows";
}else if(navigator.userAgent.indexOf(“Mac OS X")>0) {
return “Mac “;
}else if(navigator.userAgent.indexOf(“Linux")>0) {
return “Linux";
}else{
return “NUll";
}
}
方法3
var osInfo = navigator.userAgent.split(“;")[0].split('(')[1];//判断系统
if(osInfo == “windows")
{
alert('windows’);
}
else if(osInfo == “Macintosh")
{
alert('Macintosh’);
}

JavaScript

Posted by arkgame