|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
O+ V& G W9 s; `2 S; a8 A6 ?( [+ B) }! V) u
<SCRIPT LANGUAGE="JavaScript">& K& Q; I, \: M" S+ D
function mobile_device_detect(url)
+ r5 m7 j) g; f+ m" d) _9 @. L {' Z% m4 r e- v/ G" p9 W. y+ h
var thisOS=navigator.platform; i* K- q( Q$ U
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");% {+ o3 b+ v7 B- C1 B8 ~
for(var i=0;i<os.length;i++) Z" D$ o2 B0 Y0 ^7 O1 x
{. @2 R% x- i% C2 o: _, `+ }
if(thisOS.match(os[i]))
# B: k' t6 F% i4 x% g {
/ w& K/ v+ G& S0 B' t' k window.location=url;- Q- G( B& z5 V
} y* d) K5 d8 S! j9 L
6 H" H0 p5 |! a! D% g/ B* C0 K
}: t, _# B0 d" A+ j& V2 @) ^' a r
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
8 I- r) e& H0 a- B if(navigator.platform.indexOf('iPad') != -1)6 y$ \6 E; @1 F! e! O
{
9 R$ ?: e5 n) S& Y# k window.location=url;
" v o8 ~2 @' O$ Y! I }7 `$ i3 B$ _/ X* V
//做这一部分是因为Android手机的内核也是Linux
/ C/ `( T' U9 R4 X, a. { //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
% ~$ v& J: Q. c4 M. L var check = navigator.appVersion;
! ^0 q$ c# P3 v8 n if( check.match(/linux/i) )
+ \. N j* M7 |5 D {2 J# ^0 K; k+ [" r1 u% P
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件3 ]! h: b" ~. m
if(check.match(/mobile/i) || check.match(/X11/i))
/ I, ?* h4 Z: \ {' R1 ?) z: `1 A; I0 g5 a5 J/ l6 m
window.location=url;
8 z. E$ n& f" q& l0 I5 B } ) a' `& I+ z3 R, Q2 v
}5 C: o" D7 a. M7 S b5 Y% _
//类in_array函数
# v+ \- f3 p; r9 s8 V! Y1 e* a- a J Array.prototype.in_array = function(e)3 c1 s& z7 Z4 X5 w$ x3 C% B
{
4 O- X* r$ N' ~& K+ ]4 K for(i=0;i<this.length;i++)
# C3 @6 O/ a9 V/ j {; \% k. ]8 S' S) U/ U0 p; B* K
if(this[i] == e)
: U2 ^, z/ }. u) M" Y( O# M5 z+ n+ Q L return true;! Y" `3 W0 o2 B( }: M, @+ |
}
( S6 c( Y+ c {6 I1 l return false;
) @' a0 b; M8 @0 n( E* E2 U; ^ }" E: \4 W7 A B' J
}
3 c0 ~7 x3 t4 s$ z1 z; x mobile_device_detect("http://m.xxx.com");4 Z" q3 b u* o3 B' V% G9 p) u1 c' k
</SCRIPT> |
|