|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
' _3 F$ S5 l2 f& @4 q( X9 y4 `8 ]
' |" v( {3 F/ d) K9 F- o3 b- {5 u" e<SCRIPT LANGUAGE="JavaScript">, z& S l2 v+ s# P+ `: G
function mobile_device_detect(url)! U1 b. ~/ `' ?
{% e0 D: W8 Z# |/ g) Y/ ~8 r
var thisOS=navigator.platform;
/ P. |* j: w5 }/ h" e var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
6 n5 E2 W9 g5 }% R) q0 z for(var i=0;i<os.length;i++)4 r( `4 ]# e" T
{" N; K a4 M$ D4 b. C
if(thisOS.match(os[i]))
" J5 W5 P' o8 @ {
. v" H4 m$ H- Q! T/ | window.location=url;8 D0 s* h" w4 R, Z1 M* A1 e5 n
}
( w& n5 z- g. F0 A / w- t3 R9 M8 I; _# |
}) ~9 Q, e, }6 o! v+ ^$ {1 o& g& [
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认" ~8 C0 G% }& \
if(navigator.platform.indexOf('iPad') != -1)9 A1 O9 {4 a1 |0 Y: `# A
{
5 Q/ Y# {- H \5 N" V window.location=url;0 |8 y& J+ Y4 z5 Q+ V' `, x
}6 V* o2 X) D+ L1 g J7 g
//做这一部分是因为Android手机的内核也是Linux
# o) `: z! V" h ]- p# o- `- @ //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断" _$ V O1 m6 e4 a0 x, }8 V
var check = navigator.appVersion;
. }; I/ i* p6 d4 M9 o T3 Y if( check.match(/linux/i) ), w4 X& u; u X9 _: e: ~5 B
{8 E- ?: @5 I0 a3 E h
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
" W& n% Q, o% o$ B* ], {7 D5 ~ if(check.match(/mobile/i) || check.match(/X11/i))
3 T; ^* {1 ?3 u; W4 N; d) S! J7 C. F {0 R: o1 j) r: G3 _0 Y
window.location=url;! l+ k8 |5 X0 p; o
} 0 `9 J$ t. t9 p
}8 _7 P% A# G k7 {1 D
//类in_array函数& { P8 l; H+ R/ X8 E( z
Array.prototype.in_array = function(e)
) {7 x/ i% u# y) Q9 O% [+ ? {' m- |: U- T8 k/ Z( K+ S
for(i=0;i<this.length;i++)
5 ~0 y+ e `) i* i* A {
, f8 z2 Q& g& r( U: c8 A if(this[i] == e)
3 |+ ^2 N: x3 l' c* n+ F* Y return true;
& \$ M& t, t3 ]( a. O& l( D5 Y% n& L }1 ^: \2 m, u( w' z/ y s1 O( I
return false;& D+ @1 H/ d; M" O. S+ D
}! N1 `7 x& T/ r# p; F5 T
}
' U. v% ^/ k0 Y5 @; \ mobile_device_detect("http://m.xxx.com");% E5 k7 z# m5 e7 A& `0 D* \+ g
</SCRIPT> |
|