判斷當前的瀏覽器是pc還是移動設備,如果是手機,就跳轉到對應手機端網站
var sUserAgent=navigator.userAgent;
var mobileAgents=['Android','iphone','Symbian','windowsPhone','iPod','BlackBerry','Windows CE'];
var goUrl = 0;
for( var i=0;i<mobileAgents.length;i++){
if(sUserAgent.indexOf(mobileAgents[i]) > -1){
goUrl = 1;
break;
}
}
if (goUrl == 1){
location ='http://www.baidu.com';
}