1、通过判断浏览器的userAgent,用正则来判断是否是ios和Android客户端。代码如下:
2、检查是否是移动端(Mobile)、ipad、iphone、微信、QQ等:
使用方法:
检测浏览器语言:
3、判断iPhone|iPad|iPod|iOS|Android客户端:
4、判断pc还是移动端:
使用Navigator对象的属性信息可以达到你要的效果,以下为Navigator的例子,你可以根据需求,进行判断后,做出相应的提示。<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="YangHui">
<META NAME="Keywords" CONTENT="YangHui">
<META NAME="Description" CONTENT="YangHui">
<SCRIPT LANGUAGE="JavaScript">
<!--
/**
* Navigator对象的全部属性信息
*/
function navigatorInfoAll(){
var msg = "浏览器信息如下\n"
for (var propname in navigator)
{
msg += propname + ":" + navigator[propname] + "\n"
}
alert(msg)
}
//navigatorInfoAll()
/**
* Navigator对象的部分属性信息
*/
function navigatorInfos(){
var msg = "浏览器信息如下\n"
msg += "appName:" + navigator["appName"] + "\n"
msg += "appVersion:" + navigator["appVersion"] + "\n"
msg += "userAgent:" + navigator["userAgent"] + "\n"
msg += "appCodeName:" + navigator["appCodeName"] + "\n"
msg += "platform:" + navigator["platform"] + "\n"
alert(msg)
}
//navigatorInfos()
/**
* Navigator对象的属性实例
*/
function navigatorSimpleVersion(){
var msg = "当前使用的浏览器为:\n"
var browser = new Object()
browser.version = parseInt(navigator["appVersion"])//browser.version = parseInt(navigator.appVersion)
browser.isNetscape = false//Netscape Browser
browser.isMicrosoft = false//Microsoft Browser
if (navigator["appName"].indexOf("Netscape") != -1)
{
browser.isNetscape = true
msg += navigator["appName"]
}
if (navigator["appName"].indexOf("Microsoft") != -1)
{
browser.isMicrosoft = true
msg += navigator["appName"]
}
alert(msg)
}
navigatorSimpleVersion()
//-->
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>