|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
! P( j+ m7 \, ?% e
8 O# m: A0 P# J3 s7 c( H! Q; ?& L. b<SCRIPT LANGUAGE="JavaScript">7 f: S* v! y* H+ i" ~3 n' R+ T1 a
function mobile_device_detect(url)
6 K* z4 p; f M% g5 h {) c* D6 d( @1 i) _
var thisOS=navigator.platform;; v" A% b% T+ D0 B# 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");1 u. |: X% A _# U0 g% K
for(var i=0;i<os.length;i++)
6 E, b* {1 q3 W; }+ n {- ?# I0 f1 y+ N& f
if(thisOS.match(os[i])), k9 e( k9 b! n Q
{ " [% z3 D6 o6 B& W/ A: h
window.location=url;4 N% U+ M7 x3 K, N3 v/ c% J2 v g: D
}
1 s0 A8 m! k+ @8 e l3 ^7 A , e* s! D- j8 ~7 m
}- b" e5 p* ~0 E% L1 Q
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
# N5 |6 k x: ^6 h! T if(navigator.platform.indexOf('iPad') != -1)
+ u( d" }" y% x. w( w! Q {; S" m% t0 o7 e( i N* Q
window.location=url;
1 H3 d# I R, s8 m5 }8 T( u& O3 R }. z% j9 x5 W! n+ O' g* q
//做这一部分是因为Android手机的内核也是Linux
5 G1 U F4 r% Q& p //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断, j* B% c' Y: }% a2 ]4 f
var check = navigator.appVersion;4 P" v# Z- f: C: A* F
if( check.match(/linux/i) ). x% t! }4 p: T
{9 X& O) M4 A! ~, q
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件4 |% `* k7 T$ q4 j8 ~
if(check.match(/mobile/i) || check.match(/X11/i))
; y* O. p9 g! G. s {! K5 ~8 Y% h- ?: U: u. y
window.location=url; f$ @2 _5 w5 |
}
& Y% q% b8 D" o5 f. X# N }3 o9 }0 ?" {9 w1 ~7 m6 d. a
//类in_array函数4 ]: }! w) Q% {) ^
Array.prototype.in_array = function(e)
2 ~. Q* z. b$ r {
4 j, p# R+ w a. ~2 P; o# w for(i=0;i<this.length;i++)
5 Y# l) ?8 }& I9 H {$ c% O; {, a5 X4 X: M# H
if(this[i] == e)/ Y9 R3 ?' N: s8 q
return true;
! T0 A0 \8 Q' G6 s# G! T5 d }& g: Y5 A% \& Y) v2 O" [! Y- |
return false;) ]: C7 D' X/ P2 P
}
) a( W" X% y& F- A }
" x' Z% N7 G g+ ~. U Y mobile_device_detect("http://m.xxx.com");5 {/ K$ ?$ s2 \# x) `& B$ T
</SCRIPT> |
|