标签:cWeb blog http java os 2014
时下,许多web网站都有自己的手机建站,当用移动设备浏览网站的时候,我们希望能跳转到手机网址上,下面是一套并不是很完善的代码,高手可继续完善。
代码贴出:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>js判断设备类型是移动设备还是PC设备</title> <script type="text/javascript"> // borwserRedirect (function browserRedirect(){ var sUserAgent = navigator.userAgent.toLowerCase(); var bIsIpad = sUserAgent.match(/ipad/i) == 'ipad'; var bIsIphone = 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) == 'web'; var bIsCE = sUserAgent.match(/windows ce/i) == 'windows ce'; var bIsWM = sUserAgent.match(/windows mobile/i) == 'windows mobile'; if(bIsIpad || bIsIphone || bIsMidp || bIsUc7 || bIsUc || bIsCE || bIsWM){ window.location.href = 'http://www.163.com/'; }else{ window.location.href = 'http://www.baidu.com/'; } })(); </script> </head> <body> <h1>pc浏览</h1> </body> </html>
js判断设备类型是移动设备还是PC设备,布布扣,bubuko.com
标签:cWeb blog http java os 2014
原文地址:http://blog.csdn.net/ruizhengyun/article/details/36662055