JS實現識別電腦瀏覽器和手機瀏覽器
http://blog.csdn.net/li_magic/article/details/53215140
<!DOCTYPE html>
<html><head>
<meta http-equiv="Content-Type" Content="text/html;charset=UTF-8"/>
<title>識別電腦瀏覽器和手機瀏覽器</title>
</head>
<script type="text/javascript">
var system ={};
var p = navigator.platform;
system.win = p.indexOf("Win") == 0;
system.mac = p.indexOf("Mac") == 0;
system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
if(system.win||system.mac||system.xll){
//如果是電腦跳轉到百度
window.location.href="http://www.baidu.com/";
}else{
//如果是手機,跳轉到hao123首頁
window.location.href="http://www.hao123.com/";
}
</script>
<body>
</body>
</html>
js判斷是電腦瀏覽器還是手機端瀏覽器,並根據不同的終端跳轉到不同的網址
- <!DOCTYPE html>
- <html>
- <script>
- function browserRedirect() {
- var sUserAgent = navigator.userAgent.toLowerCase();
-
var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
- var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
- var bIsMidp = sUserAgent.match(/midp/i) == "midp";
- var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
- var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
- var bIsAndroid = sUserAgent.match(/android/i) == "android";
- var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
- var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
- if (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) ){
- window.location.href="http://blog.csdn.net/zml_2015";
- } else {
- window.location.href="http://m.blog.csdn.net/blog/index?username=zml_2015";
- }
- }
- browserRedirect();
- </script>
- <body>
- </body>
- </html>
js判斷手機瀏覽器作業系統和微信瀏覽器的方法
投稿:mdxy-dxy 字型:[增加 減小] 型別:轉載 時間:2016-04-30 我要評論
做手機端的前端開發,少不了對手機平臺的判斷。如,對於app下載,就要判斷在Android平臺下就顯示Android下載提示;在iOS平臺下就顯示iOS下載提示http://www.jb51.net/article/83344.htm今天就為大家介紹一下用js判斷手機客戶端平臺及系統平臺的方法:
?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<script
type= "text/javascript" >
//手機端判斷各個平臺瀏覽器及作業系統平臺
function
checkPlatform(){
if (/android/i.test(navigator.userAgent)){
document.write( "This
is Android'browser." ); //這是Android平臺下瀏覽器
}
if (/(iPhoneiPadiPodiOS)/i.test(navigator.userAgent)){
document.write( "This
is iOS'browser."
|