|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。! j3 Z0 L0 i2 M4 O
6 B) |8 ~9 N% j& I<SCRIPT LANGUAGE="JavaScript">8 v0 R J, z9 Z1 w$ T* P
function mobile_device_detect(url)
2 d4 k& X3 S$ l9 ^# S {5 h# @$ [# e! k. X& R: r
var thisOS=navigator.platform;2 n) O4 |) R. O4 N6 z, b" g) O7 c
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");7 k$ \7 E; s, s+ a/ R- a
for(var i=0;i<os.length;i++)
/ {* D+ D) q6 X% r3 {9 }9 | {# s- r. \: u# T: P) e5 |1 w+ l
if(thisOS.match(os[i]))
* M* l' S( u/ `6 i: N { 1 O2 f! W O% t6 a# s2 c
window.location=url;; h7 S% Y8 Z4 ~0 U
}1 _) H+ Q4 o/ i" w8 a8 n
) B% N7 m6 h6 ] }
}
6 t3 X4 Q, ^! X7 o2 `5 z! c1 o //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
* {: k1 e* S; D1 C$ W! J1 L if(navigator.platform.indexOf('iPad') != -1): ~+ s% d* Z1 w5 |* K- x' S. _; A
{9 C. `8 t# c0 I0 u" T
window.location=url;6 x6 N R, O0 F* k# v8 Y
}
6 ^3 s/ K3 c3 X& g6 @9 U) f8 K //做这一部分是因为Android手机的内核也是Linux
* v) g% S6 S( F: _ k) w8 g- p //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
0 a/ P! R9 ^4 P% h& U: k var check = navigator.appVersion;
8 h) }# ^+ Y: k; {$ {% F if( check.match(/linux/i) )
$ Q- v2 c4 G# n9 E" l {% \3 f5 N. i8 ~9 S8 b
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件, _$ h' q/ C3 c
if(check.match(/mobile/i) || check.match(/X11/i))
1 b6 k0 H6 t( m/ Q" q( ~: V3 r {
' a! b" N9 B$ r+ N6 t$ _ window.location=url;
* H8 L" R- I4 C( m. W } F" T: G/ _' \' q- I2 [$ F' [/ W" f2 W
}0 y4 P' Y- z! d% n
//类in_array函数2 K! ~0 d+ n) Z8 @
Array.prototype.in_array = function(e): [ d$ C4 U' l* v; R% U0 F: q- K& _
{
" D% f: N: l* G! \ for(i=0;i<this.length;i++)
! a* q' {( o X- \% I {5 _% c* y& g S' F
if(this[i] == e)7 W' ~8 \2 E7 e Z9 G1 V
return true;) h/ L" ], U" G3 g, i
}
* G( f8 Q0 I( `3 E* M return false;
; X4 A- c ]9 U7 \+ g+ N! e* ]4 n }
2 F. ~: A! T3 k- r }
9 t+ n. N" x+ w/ d( k# C; v* ^& j mobile_device_detect("http://m.xxx.com");
% {3 U" l8 t, l/ R4 p/ C$ X </SCRIPT> |
|