js 手机 判断 手机 移动 手机浏览器判断
function initnavigatorurl(){
var sUserAgent = navigator.userAgent.toLowerCase();
if(sUserAgent .match(/iphone os/i) == "iphone os"){
location.replace("http://XXX/m/");
}if(sUserAgent .match(/android/i)){
location.replace("http://XXX/m/");
}if(sUserAgent .match(/windows mobile/i)){
location.replace("http:/XXX/m/");
}if( sUserAgent .match(/midp/i) ){
location.replace("http://XXX/m/");
}if(sUserAgent .match(/rv:1.2.3.4/i)){
location.replace("http://XXX/m/");
}if(sUserAgent .match(/windows ce/i)){
location.replace("http://XXX/m/");
}
}
initnavigatorurl();
如果只是单纯的判断 PC和手机端就使用:
function goPAGE() {
if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
window.location.href="你的手机版地址";
}
else {
window.location.href="你的电脑版地址"; }
}
goPAGE();