|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。& v# A, Z, x# c! i" H$ L7 t
1 i( T2 l7 F9 ?2 N: c9 a<SCRIPT LANGUAGE="JavaScript">+ f( Q- W5 I' u
function mobile_device_detect(url)9 z: t- w2 L4 k
{! |# V' b; k2 L9 K
var thisOS=navigator.platform;: V# Z. D: t4 \5 ^1 }$ c9 G. w
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
, n8 F$ [7 d ? for(var i=0;i<os.length;i++)
9 i5 c; ?2 H8 [ {2 R6 O# z9 w/ K9 v- \
if(thisOS.match(os[i]))
4 S3 k7 u9 H7 t. S! V9 w, b {
- K' J6 p/ `5 g! C window.location=url;) W8 e3 m% h0 u8 r f; v( j
}* O4 i6 T: m. l- o
5 \6 C& b. H8 E) a( l: A8 j" v }
5 X( U) f( ?6 Y5 z //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
/ v k/ C6 U) u) R3 k: I if(navigator.platform.indexOf('iPad') != -1)+ I$ ~+ k5 v0 L. h
{
# Q2 u. A+ K8 B; \1 I6 t window.location=url;
" `- G9 O" v4 Q }+ \- `# t: p! e0 W9 q3 B
//做这一部分是因为Android手机的内核也是Linux$ y+ o6 H' t4 [5 b, j0 F
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
8 a. O5 F, Y$ H* F* W8 ] var check = navigator.appVersion;
5 {7 X B- P: }' w2 h4 q if( check.match(/linux/i) )1 O4 m( \0 _! p. b
{
6 \% x1 h! W0 D2 i //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件0 L; t( G, e& z0 a D6 B$ ?
if(check.match(/mobile/i) || check.match(/X11/i))9 Y* w9 f2 u, ]+ g1 W3 H. G8 U$ V7 Y
{
+ _: u- F7 R) U( j$ z4 E0 ~ window.location=url;/ l& }8 X- o1 G& {) q
} / v% F$ G0 L/ W; f, m
}6 [7 k8 W6 S, M$ ?+ z- g
//类in_array函数
6 N: g- I8 l; O* `$ f. u5 c l. l Array.prototype.in_array = function(e)* m$ y$ o' k8 k; h9 i, a9 B
{) H1 G5 N# s7 R- B# p2 F
for(i=0;i<this.length;i++)8 |6 k. }8 n* `7 y: M4 |. e$ m
{
# q* Z+ O5 c6 N: g# r6 S6 G if(this[i] == e)* }; ?# \+ z9 n
return true;
6 V* l/ Q( _9 u% c }
# a" n- ~) N6 ^: d) \* q return false;
N% Q3 z% F; u9 ~! u5 P }
9 E2 D3 |* X. Z! c; r0 s6 p }
+ x7 e7 h p. J9 F _ mobile_device_detect("http://m.xxx.com");
@3 B7 z' u. ~ </SCRIPT> |
|