|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。3 d6 _4 `1 [" H1 ^, U q
$ t! l3 b4 t* [: J# u5 p3 m<SCRIPT LANGUAGE="JavaScript">
; b8 o# B8 m3 V8 v function mobile_device_detect(url)
b- c# Z, Z) E. Q {
. s& q" t. A0 q( Y0 f9 ~ var thisOS=navigator.platform;
m: F. {9 K3 o- g, r% b var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
' O X% d. Q" O, _0 e for(var i=0;i<os.length;i++)
$ d8 @) T; S7 T1 J2 R# I* B" l {7 L+ D- ~* f' R
if(thisOS.match(os[i]))
* W8 }& ?1 R% @+ t. k, J4 m M { $ E9 j/ T& {4 i+ U) r! B
window.location=url;
9 V# p! L$ H7 E e" j3 @* x }
/ [: [4 c# o' G3 ? p
; G8 v: r; b& W }+ i' W8 t# U" x; e8 _
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认3 @) X- t; t" E& n7 n
if(navigator.platform.indexOf('iPad') != -1)6 R3 ]6 E+ H, Q' a6 c; i* M% r8 T' ?
{: Y) T1 Y$ f8 _* f$ ]: ~) ^0 r
window.location=url;
5 b7 K% D8 ?5 o9 F3 |: R7 B }" o+ n' |8 `9 f2 M
//做这一部分是因为Android手机的内核也是Linux
2 z! Z6 X. X' _# `( y$ s6 x //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断+ d- V3 P3 i) y% X: J2 `; h% W8 u8 b
var check = navigator.appVersion;1 @; t+ m8 j; H" i
if( check.match(/linux/i) )
: k, g% p7 }$ e. _ D9 N {! q' V' q4 W7 n# m
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
0 i$ r1 y- b }! v. k" X if(check.match(/mobile/i) || check.match(/X11/i))! a: z0 v4 P/ F& ?
{* w; I# X4 K( ~2 s/ Z7 o
window.location=url;4 }3 {( V, [, q4 c0 f
} 1 n* e4 ~3 O7 x6 S7 u+ e8 ]
}. z* u0 K! F, k0 E# H F
//类in_array函数
9 _4 {; A* d- e$ X, h0 [ Array.prototype.in_array = function(e)( V) U Z! D' S
{1 u) s8 h. I0 r1 t) `
for(i=0;i<this.length;i++)5 L( `8 C0 \# g7 E* V+ w1 O
{
4 Q1 y! o; [3 o! s if(this[i] == e)
$ ?8 `! R- P7 x$ e( A/ B; B; E+ h return true;
* F' ^6 v" Z$ [4 y, X1 M6 E/ J' z }9 P1 k+ U4 y! z% A. C
return false;8 `1 ]) L" C, B. C7 \
}8 u1 J" p: D& F& [
}
9 C. \5 p8 ~! o8 G, }) v mobile_device_detect("http://m.xxx.com");4 h) H# o# ]4 X0 b
</SCRIPT> |
|