|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。, D- F# j; g. W7 D% ~
; ]$ f w [5 t3 F# C& w( m<SCRIPT LANGUAGE="JavaScript">* Y: r% g# w- S9 H& w
function mobile_device_detect(url)6 E: R" d$ v" ~# U
{
6 a$ Z0 E3 e ^. N var thisOS=navigator.platform;
2 h* O5 J4 P& e0 ^7 ^ var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");! ]2 F1 a+ H1 N2 T1 P- N# V9 [
for(var i=0;i<os.length;i++)
6 M2 ~, e9 S2 P" @* V$ V {/ e# w+ y4 w/ F
if(thisOS.match(os[i]))0 s" p# ~. L$ j! i/ G
{
' u0 v( p: b# W- D window.location=url;
0 c$ l+ r) p' \6 g. y }
0 g/ E' [7 R* t: W/ P 4 F5 l- b6 C6 l$ V1 t# H
}
8 M, a6 x6 t: S7 l6 O! ~4 Y* r" A) M' s //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
4 L/ B8 r. F* L if(navigator.platform.indexOf('iPad') != -1)$ l: o* Q/ b, X7 z2 O6 r# O0 x
{2 e( g3 E, G- e' @6 x6 W$ E
window.location=url;
' c n m5 l2 B* v8 i% A4 B }) K; `3 z, y: C6 F9 a: ?! |$ l
//做这一部分是因为Android手机的内核也是Linux
" k, R0 c: z! k/ l5 O* {3 z& x //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
$ q' Z# Z0 N, M8 k3 v var check = navigator.appVersion;
# x2 E' M' ?- o" q if( check.match(/linux/i) )/ j% t7 U1 y# f& y# t8 ?1 e
{/ f: P. g& T+ W6 ?% ?0 N, n
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
4 E1 d% X7 n4 z3 x% Z. | if(check.match(/mobile/i) || check.match(/X11/i))& l% B3 Z3 [. w, G' `; x
{" {: @( R- W5 A @5 S6 A
window.location=url;
0 W2 ^& P2 b' ~, m" J$ O9 w, a: k1 H } 6 t Y! c8 {. C6 u* O0 D- Z: ?
}9 e6 g1 ` M8 E' C
//类in_array函数( H/ h. ]$ ~. R* q% K/ ~
Array.prototype.in_array = function(e)
! f0 q5 M: W4 n# o" B, W% v& R {7 n( u4 |. ]5 L* n/ @, Y5 H
for(i=0;i<this.length;i++), G+ \) s9 H* Z: {: T7 L2 l2 |$ X
{
6 z% o+ `! ~: e: O d if(this[i] == e)" k! S3 O1 f) I9 {* d2 Y
return true;) x' `1 w. l9 ? p0 E( |8 O
}( l# X2 }3 l9 N! b
return false;
4 P7 J3 U J* F* Q }! Z+ N- r8 ]/ L1 \
} ) q& q2 u' W0 ]
mobile_device_detect("http://m.xxx.com");# J$ M, U) J! _: @: U! I: M! x
</SCRIPT> |
|