方法一
const detectDeviceType = ( ) => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i . test ( navigator. userAgent) ? "Mobile" : "Desktop" ;
detectDeviceType ( ) ;
方法二
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) {
console. log ( '手机端' )
window. location. href= '手机站链接' ;
} else {
console. log ( '电脑端' )
window. location= 'PC站链接' ;
}
}
browserRedirect ( ) ;
方三
var system = {
win : false ,
mac : false ,
xll : false
} ;
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) {
} else {
window. location. href= "手机站链接" ;
}