|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。8 w" C: t- ^- j. }% _
! H) H. R8 y2 C<SCRIPT LANGUAGE="JavaScript">
8 o6 C& V: [& H( n( \7 ]3 K7 ^ function mobile_device_detect(url)
1 C% ]( i4 i8 O( c# B/ G) S5 b2 d {2 K2 ^+ j: c* q. x
var thisOS=navigator.platform;
# q) |. {& s7 U6 N3 Z3 x/ d var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
( O& K7 l+ o- a( G6 u; R4 ^9 H& t for(var i=0;i<os.length;i++)7 e6 ]) G: ]% Z
{/ t0 }& W- ]" X( k4 H6 X+ z; e
if(thisOS.match(os[i]))
; Y! c/ ?; C( S/ ]5 E { / ^* |9 d; {" a9 k; E
window.location=url;
1 m! Y5 H" ]- z0 ~& H }
. A' j; W, q# t/ n : c; t6 a1 _/ x2 \4 a& t' ]1 Z
}
( F" A, `5 |8 _ Z9 O' Y S- B //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认/ a$ i* T6 R1 x* }& F" C
if(navigator.platform.indexOf('iPad') != -1)6 U! u& i+ [) D* D
{
( B1 U4 L9 i( D2 L window.location=url;
n8 E) N+ W& [9 y }
+ Z+ p+ N8 f5 M( R4 z //做这一部分是因为Android手机的内核也是Linux& \4 t6 X6 T4 [0 f+ F
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断8 ?& c }; B8 h9 j6 h: }; Z$ S
var check = navigator.appVersion;- j. L; N4 i! T% B
if( check.match(/linux/i) )0 U% I; i0 d* N- J" L) w3 ?
{) |1 M/ Z2 H$ _7 W# F r/ f3 O5 C
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
. y9 R1 E1 M! O3 g, f if(check.match(/mobile/i) || check.match(/X11/i))
/ S4 a2 }1 P* z {1 }; d9 W. G, Q+ d* x4 ~8 ]1 h
window.location=url;) F8 ]3 x* W7 i4 L' ]% ]" A3 u( m
}
0 a$ C8 c$ }- D }
" Y0 s3 c9 e7 K y6 B7 n- ~' A- B //类in_array函数
. u8 d3 }( g1 m, b& ?" c: J' F Array.prototype.in_array = function(e)2 j6 {+ H4 x% g6 D/ o6 R
{
7 g+ H: _! D0 h) g6 i8 q for(i=0;i<this.length;i++)
0 H; Q) a) s, m, w/ U; y: W8 q/ W' ~: u; k+ C {4 s3 m; E+ D' V A9 ]
if(this[i] == e); s V; x/ i6 o I9 P9 Y
return true;
' F( P4 `& N8 t# M0 a- b3 ] }+ U3 L7 E7 G/ p; @ N4 ~6 R
return false;
2 ^6 K$ _3 e$ @- ^ }
8 J0 {* s& n, S; R } ) K. A% o& j, d. h. F
mobile_device_detect("http://m.xxx.com");. M0 {$ R9 ]6 M8 x1 Y
</SCRIPT> |
|