|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。4 V: }4 O, @& F4 \# K
% q+ {9 T8 i2 b$ ~ Z2 L<SCRIPT LANGUAGE="JavaScript"># I% M) G( d% {, E: l/ r( C8 e
function mobile_device_detect(url)
7 F+ Q' r8 s/ g1 j* s+ Y, ? { H6 b9 l4 L5 q7 X7 [( l1 h
var thisOS=navigator.platform;6 ]" I" }7 k' 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");
' b: R1 R! {$ R/ O3 D& @% b; y' | for(var i=0;i<os.length;i++)
, a1 k+ E1 g( \. V {6 z H* ?: y( X9 t" c1 s, p
if(thisOS.match(os[i]))
0 G3 q e; u6 B$ J: H% ?+ K! g { i. o6 l9 O9 w; i8 t
window.location=url;( N1 [0 A: i1 q- w' k. \
}
. D! h& J$ O; _) q( n% { ; _0 M( e5 S6 n3 Z. Z/ w/ o
}
h+ g$ e) |$ }6 q //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认' l; L& Q2 A& k1 B6 X
if(navigator.platform.indexOf('iPad') != -1)& j7 s/ S8 i5 u! \+ y
{: p. i' P+ I9 ?2 Q Q5 @) c
window.location=url;, U2 H# @$ K* x1 S3 n0 R& ^( G6 F
}! c9 W: @6 Q p) G6 I7 l
//做这一部分是因为Android手机的内核也是Linux) J4 `6 Q2 H! V4 w' f2 t$ q5 ?1 M
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断7 w2 c( ]6 y" I+ I: f
var check = navigator.appVersion;
4 q1 P# i/ z- g# t% Y9 f! I if( check.match(/linux/i) )
Z) x5 S1 q5 U: }; o {& f6 R: L7 q; C9 v$ J
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件+ j i3 J o8 U) B
if(check.match(/mobile/i) || check.match(/X11/i))
) l- P6 V+ k! N( l& ` ^ { J% N! h$ T( \- X/ e! k" f
window.location=url;
' f! Y. L0 }6 H6 B# Y7 g+ H }
, G% }3 I, X6 [* O3 [3 `2 D }
1 ^! a+ ~0 @- a' x, c! J //类in_array函数
- y% n& Z" P) t/ n+ B& e$ h Array.prototype.in_array = function(e)8 g" H- u' Q, w9 L
{+ e2 J, j7 }& M
for(i=0;i<this.length;i++)
8 i* b/ W! m' G5 Y' Q {
, d9 H: @2 ~( `* u8 S if(this[i] == e)$ e1 n, ] I2 ?
return true;
6 u9 Z0 B, I9 y' n& r% A }0 ~' B# |/ [( E L8 d k
return false;7 c. K/ b/ C7 D7 E* s
}
% A3 G' E V- [ } 1 v( _& k1 D& L% M4 q# W, k
mobile_device_detect("http://m.xxx.com");& X+ Z) [' c! h! L2 E
</SCRIPT> |
|