|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
' k7 d- R4 h9 m8 A4 I1 o' Y5 R# @' n3 Z. v7 n
<SCRIPT LANGUAGE="JavaScript">
( _+ Q5 S& {4 Z( J1 L' A function mobile_device_detect(url)! U: M7 t' O! X9 L
{6 ^9 n) O7 s5 L" a7 D0 W( |2 ]
var thisOS=navigator.platform;
9 _0 N0 o3 N2 G4 v var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");' G& ~6 x) f- L3 ~0 o- [- U: r8 f% f; i
for(var i=0;i<os.length;i++)
3 Q: i0 U, F0 ]$ j8 c0 E3 F {
" _6 O7 @$ O, P& x if(thisOS.match(os[i]))4 H) C7 b7 } _" p1 G
{
. `; H* G0 h2 G window.location=url;- D( I& S# \0 v
}
2 v- C' ]3 b( C, h/ I , k* o* k# r$ z: H* P; X; v
}
6 h" H6 v, F) ]! _7 s* W" x //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认$ V. X' L7 Y5 U
if(navigator.platform.indexOf('iPad') != -1)9 v& g! H( E9 i8 `( u9 Q
{- a) S& H: Y( X w( Y, Q" f
window.location=url;
* d! W4 t, _! A |; L }- ^- _& C& U; ^. v( V
//做这一部分是因为Android手机的内核也是Linux! |2 \' C7 |" P! i$ t4 L
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断& Z3 T4 J4 m+ p+ ?) R
var check = navigator.appVersion;, M& X9 @& ?6 d# Z$ ?
if( check.match(/linux/i) )! q* b! p$ [6 S8 W+ l: u5 X
{
4 M0 a! y5 W- T1 G( n) L //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件, ^4 ]1 W' x/ u7 o( e9 b
if(check.match(/mobile/i) || check.match(/X11/i))! v& l% m3 _+ R" O' x/ ^6 @
{; F/ c' b3 \+ V c. b
window.location=url;
" ?3 S) K6 Z1 J4 ]# H } . r! o3 j. |" R0 M" v5 K
}
! Z b6 l* K5 Y //类in_array函数2 Q( Z2 _- Z O: c$ w3 \+ k9 P
Array.prototype.in_array = function(e)$ r6 O: c, B3 \
{8 q/ b6 X4 F1 |8 L& Q5 G/ j9 Q1 t
for(i=0;i<this.length;i++)
" _- ~) s6 E, M! ] {) y2 w' W1 H4 r( N# {
if(this[i] == e)4 @1 v2 ?. H2 ]% n
return true;
5 ]4 H) J* w) M5 ^% F }
7 v+ U! I n; x+ G5 R2 X return false;
6 s7 L' u4 I- }4 c! h5 S( ]/ K }
- I' s, P7 i. R& F* m& ] }
. N2 y% k: z Q* P" o mobile_device_detect("http://m.xxx.com");
/ }, T, G" E* H: i </SCRIPT> |
|