|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。- L% g7 Q" w; Z7 N* ?* u; e
4 a N1 Q' Q# f5 N2 M<SCRIPT LANGUAGE="JavaScript">. o- E U( c5 P2 l4 D6 T: d9 ~
function mobile_device_detect(url)
' c* T" b! g2 f$ Z- m {
6 x0 `' z: d2 m) i, x var thisOS=navigator.platform;
5 ?6 q4 L) z0 o! s: o9 h) {/ ? var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");) ]2 V, L9 S K' J) P+ }8 `
for(var i=0;i<os.length;i++)0 d# X% a5 M5 ^$ g: Y
{
$ h1 e4 I; _+ P( Y7 t if(thisOS.match(os[i]))
% B6 `2 o0 q1 _* F2 ] {
! }4 O# q/ e. D( T window.location=url;
/ F; ?9 Y8 m0 @ F# v }/ L+ b+ O; u/ h5 m
; G3 U! R# U8 M9 Q6 j2 b+ ^- d }- h+ A. q( K* Q8 H3 m
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
5 d9 \: b; k) _# g7 E/ E5 B2 p if(navigator.platform.indexOf('iPad') != -1)
* A" R" O, Y: |1 `; u/ N {9 f. e# I7 ^8 m; X
window.location=url;0 `" M8 q# g8 ^# w3 z& Z, z
}! x# U0 m2 |( S3 A7 a
//做这一部分是因为Android手机的内核也是Linux$ K5 }! x2 V. W0 d
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
# }0 H6 e, T, V) x$ l X( e* ^ var check = navigator.appVersion;
2 U k- s# F8 ]% Q; U if( check.match(/linux/i) )6 L5 r! A }" l/ s; T& d
{
4 \' [( A' L* }1 e. ]6 A8 v, S //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
/ m# S+ A. f" T if(check.match(/mobile/i) || check.match(/X11/i)). a* @1 E! z+ [# R5 p3 v. ~( O" S( ^
{8 x$ j7 i% N& j* ]( l
window.location=url;
9 f$ m/ Y9 a6 |( E4 D" m } / d) p* v/ y2 o7 Q6 y
}
- n$ i/ h1 t9 |& e //类in_array函数9 s( l' M. [! l) G: v
Array.prototype.in_array = function(e)
- a9 F) y+ y+ N {
8 o2 V6 d; H& |2 j for(i=0;i<this.length;i++)
' K! \2 m( w6 I1 C: V: \ {
/ L. Q! X8 T9 z3 D8 I% W0 G9 e if(this[i] == e)6 R. \' E+ m3 s O
return true;* R' h8 U' R+ D* w/ j; J4 y
}, y* |7 M- e8 ]* Y J
return false;' Y; C, t' D& M2 j, S1 C7 v
}. T# ]5 ^" k& w$ b6 Y
} , P: O9 v& X/ G8 }
mobile_device_detect("http://m.xxx.com");
7 `! }+ U! z' c </SCRIPT> |
|