|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
% \8 \+ j9 |2 I6 z8 E3 }% W( D& ]
<SCRIPT LANGUAGE="JavaScript">
& e$ R' E) _5 F. p+ Z) E function mobile_device_detect(url)+ i' a4 w' R+ C0 z
{
* A; \; }" u; N var thisOS=navigator.platform;3 I( y) t+ V/ r6 x; o2 `8 ? L, w5 L
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/ B/ x2 [, C. K
for(var i=0;i<os.length;i++)
Z- d+ t$ n0 R* ^% Q {! S+ B: b' l9 d; V
if(thisOS.match(os[i]))# x$ _- j# x9 M
{
7 e; s" a2 a) v window.location=url;+ b* h. [1 i; j; |
}; }$ O2 c4 Q' N+ o8 F
' L& g! m: J7 O- ?
}
7 }- _$ H4 X7 a+ w T& Q, h2 f //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
* L2 x) v: [7 w4 n if(navigator.platform.indexOf('iPad') != -1)
+ `) d: U4 x. q( i {
; r! ^' w- z% j9 z3 l3 U window.location=url;
4 i) Y; n3 ?" ^: k4 n1 D }
" ~( P9 n/ x# | j( i) P0 } //做这一部分是因为Android手机的内核也是Linux7 g; u# H9 T7 [* j
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
2 Y6 b$ C f. G. F: v var check = navigator.appVersion;6 Q @% E: d( [
if( check.match(/linux/i) )
5 L' f: l+ @- o8 ]3 ^6 R {' g. K& X. ?& W, ~! o5 U6 W& r7 t' Y
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
0 \3 P4 {6 a4 P if(check.match(/mobile/i) || check.match(/X11/i))
, `& T8 R- U( ?2 Q { B' ~. |1 a- N d' m. _; ~
window.location=url;' j U6 O3 y" t( x! @
} 4 {+ {5 ]' d6 g) C" V/ c
}
' P( F! C3 q9 R" ]) e* E: q //类in_array函数" ]5 I, { R/ v, w
Array.prototype.in_array = function(e)
1 ]+ i6 A9 C ?) q$ c- @* ] {
~, j& }) ~ X* A for(i=0;i<this.length;i++)6 P# \! c( s& B2 i
{# g1 T/ x/ @1 T, ]
if(this[i] == e)) n" G1 `8 u7 Z3 m8 {/ I n7 g
return true;
+ e- ^4 x. ^' W; y% Q, c. e& i* w }5 U4 A" d6 h. A7 s
return false;
6 B* K2 y$ @0 ^) n3 H) m }
; ]) q4 l Y [5 w: l8 [% a& i" K0 z* w }
% v) J# v7 Z/ r8 `9 }2 z# A mobile_device_detect("http://m.xxx.com");
7 e! G+ j! F8 W, i </SCRIPT> |
|