js判断访问的是手机端,还是pc端
程序员文章站
2022-03-10 13:43:49
...
<SCRIPT LANGUAGE="JavaScript">
<!--
function detectOS(){
var sUserAgent = navigator.userAgent;
var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh");
if(isMac) return "Mac";
var isUnix = (navigator.platform == "X11") && !isWin && !isMac;
if(isUnix) return "Unix";
var isLinux = (String(navigator.platform).indexOf("Linux") > -1);
if(isLinux) return "Linux";
if(isWin)
{
var isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1;
if(isWin2K) return "Win2000";
var isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 || sUserAgent.indexOf("Windows XP") > -1;
if(isWinXP) return "WinXP";
var isWin2003 = sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows 2003") > -1;
if(isWin2003) return "Win2003";
}
return "None";
}
alert(detectOS())
//-->
</SCRIPT>
<!--
function detectOS(){
var sUserAgent = navigator.userAgent;
var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh");
if(isMac) return "Mac";
var isUnix = (navigator.platform == "X11") && !isWin && !isMac;
if(isUnix) return "Unix";
var isLinux = (String(navigator.platform).indexOf("Linux") > -1);
if(isLinux) return "Linux";
if(isWin)
{
var isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1;
if(isWin2K) return "Win2000";
var isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 || sUserAgent.indexOf("Windows XP") > -1;
if(isWinXP) return "WinXP";
var isWin2003 = sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows 2003") > -1;
if(isWin2003) return "Win2003";
}
return "None";
}
alert(detectOS())
//-->
</SCRIPT>
上一篇: 页面游戏的流量分析
下一篇: 两年半换第 4 份工作,做个总结
推荐阅读
-
thinkphp判断访客为手机端或PC端的方法
-
极光推送按照官网例子写的demo报错"Response timeout"但手机客户端还是能收到推送消息,而且是多条?
-
java后台判断客户端是手机/PC并返回不同页面的实例
-
java后台判断客户端是手机/PC并返回不同页面的实例
-
用JS实现复制内容到剪切板,兼容PC和手机端,支持SAFARI浏览器的方法
-
thinkphp判断访客为手机端或PC端的方法
-
详解JS判断页面是在手机端还是在PC端打开的方法
-
怎么用JS来判断设备是pc还是移动的?
-
PHP判断访客是否手机端(移动端浏览器)访问的方法总结【4种方法】
-
利用PHP判断是手机移动端还是PC端访问的函数示例