|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。) K- K6 V0 D2 @
/ `8 w$ b1 i1 C( f7 f7 B4 M+ w/ ]<SCRIPT LANGUAGE="JavaScript">
. }# s! H3 m$ L function mobile_device_detect(url)
# E( O( o* b7 L7 [" g' ` {
+ u7 S2 q$ a0 X; O var thisOS=navigator.platform;
?% Q# X4 @9 P& D0 ] var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
& u! \2 ?/ l2 j3 }/ ?6 s E for(var i=0;i<os.length;i++)
' B+ E& B; [& U# d {
! f4 u+ A1 o! j6 k d, d if(thisOS.match(os[i]))3 N5 @: A# M, w1 m/ g; K
{ * _" p( k! l A
window.location=url;, B! d/ ^% Z9 n+ W ?" w. V, G
}8 u1 h/ ^9 y0 N
) U' Z* E9 Z) V% @
}4 {7 p7 a# y$ F! y$ L
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认6 h4 a- n) _! m- l# Z
if(navigator.platform.indexOf('iPad') != -1)$ C' }- g! x/ ]) k! v+ }8 }: j
{' P" X" ^. z, q+ y1 V) [: Z
window.location=url;
$ t+ n% U% l. e2 }; Y/ M8 P }
1 |6 Z* q D% U //做这一部分是因为Android手机的内核也是Linux3 M, p L7 P# a: P1 Z$ W" \
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断) L9 m6 Z- E/ b' \
var check = navigator.appVersion;
6 }5 X4 e' |$ _- h7 w if( check.match(/linux/i) )
7 Q; N6 _' ~: j7 _. ~ {9 }- ?0 J) \- Y
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
1 ?$ A2 {. V) _$ ]# U1 J if(check.match(/mobile/i) || check.match(/X11/i))
' o0 k6 V, ]* o5 A* x: X! m U {& a1 m6 s/ _- l' X- r/ s
window.location=url;
$ i# ]* q7 R9 n2 \7 j } ; ^3 w G7 R: l/ o" [) S
}
; O1 T+ i7 k" R$ G8 O) b6 j8 C //类in_array函数
+ X {+ T; g. Q7 W+ N6 v. j Array.prototype.in_array = function(e)
* F' V$ b1 Z1 p {/ J/ C8 {5 L2 a ]% s$ i7 i& J4 b! N) @
for(i=0;i<this.length;i++)
/ Z6 h# s, J% b( F" _2 ? h {! F; y y8 x J4 A; G& Q5 h
if(this[i] == e)
0 M8 J: y7 ?1 N# H5 F" q return true;
. V/ S! E5 I- n. v& b }
- g; ?5 Y8 Y! f5 [) l return false;. [2 _) J8 c# b
}
7 X9 r* _; Q& F) n0 J1 s6 ~6 g }
: m+ U h. h# z$ v( r' ~ mobile_device_detect("http://m.xxx.com");
4 a! _3 O- K) |* ?8 ]( p </SCRIPT> |
|