Publish: 2016-01-23 | Modify: 2018-08-16
var ua = navigator.userAgent;
var ipad = ua.match(/(iPad).*OS\s([\d_]+)/),
isIphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/),
isAndroid = ua.match(/(Android)\s+([\d.]+)/),
isMobile = isIphone || isAndroid;
if(isMobile) {
location.href = 'http://m.domain.com';
}else{
location.href = 'http://www.domain.com';
}
}
//or separately judge iphone or android
if(isIphone){
//code
else if(isAndroid){
//code
}else{
//code
}
I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.