|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。% B4 y' q9 f0 |
; ]0 l7 e/ E2 a' a
<SCRIPT LANGUAGE="JavaScript">
# _& n: i9 {# ?- I function mobile_device_detect(url) x3 F1 n$ J+ m V9 r
{
- u) l. a& u( o var thisOS=navigator.platform;4 R/ _0 d, e9 X; o7 H
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");+ C3 `3 B; @/ F @6 H2 N; `
for(var i=0;i<os.length;i++)& ^, {! m% E6 {( a* k3 J6 d/ U
{) H, A/ C3 d0 Y( k$ ]4 q) ?* l
if(thisOS.match(os[i]))
4 t7 E' F; r) C4 a0 o8 ~ { ; }, h% D4 X/ k* o
window.location=url;
& M; y" q% D( b. B4 W }
^9 j7 i3 C g( K2 @0 W$ l 5 _- i# [/ C: H& A4 E% n' Q
}
, X3 c4 }! ^( ^; G) }. b //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
: a- Q7 o) K" S* P4 y9 A if(navigator.platform.indexOf('iPad') != -1)6 H) C! S- V% o' j
{- D9 M8 m$ @% E1 y. x
window.location=url;2 U6 ]. ?& t, i$ N, ^% x
}& Z' d1 U \9 ~# _
//做这一部分是因为Android手机的内核也是Linux
+ U$ P& {. A, p //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
& ]! v0 ~; T _4 f% F var check = navigator.appVersion;
0 Z" M6 C/ R F" G* R if( check.match(/linux/i) )% @. o: C0 T/ w! d! g
{4 L$ ? |: r; B. v1 m4 ]
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
) `; N) _% G6 \, _( C" K! ^. A if(check.match(/mobile/i) || check.match(/X11/i))# _+ c2 u/ e7 g3 w5 j* P
{
( r1 }3 A' o) Y# _ window.location=url;
8 F% R) z/ H( g9 ~6 Y3 N }
5 ]6 ]2 r1 R# s' r% O) v# q: a }% l4 ?. V) V F: q$ n0 Q
//类in_array函数
4 ]+ [7 t6 P' d1 r9 b4 w2 g Array.prototype.in_array = function(e)
6 q1 q' j7 r% r0 K2 [1 ]% o. s# a {
) J; V* M! `7 I for(i=0;i<this.length;i++). L, v+ r. @/ ~' y
{$ w+ \# {/ V5 z! w9 L0 n; r6 p
if(this[i] == e)$ m8 n( i. c3 {% ]
return true;/ n" |2 r. L: _ \% X' e
}
; ?/ |! _! B, {) H% Y3 Z" R: ?5 F return false;
( `( V* x3 X5 r' i0 r+ T }
; @0 d+ \% P) s0 I2 R' O, S: ] } 2 R) ]0 ]- k w, [; L
mobile_device_detect("http://m.xxx.com");
3 S' K! b! V0 Q% z4 [ </SCRIPT> |
|