|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。. @" L, s, J: }
1 g" w' n/ q G$ t/ N
<SCRIPT LANGUAGE="JavaScript">
. |5 W( ]7 P) Y# D# j3 {! a function mobile_device_detect(url)% y9 j+ g9 d ]' V- G
{
3 u/ ^7 _$ p8 E/ x var thisOS=navigator.platform;7 c) U ]" l- P+ {
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
, h7 g+ A1 `/ Z8 h for(var i=0;i<os.length;i++)/ ?. M) F- C# T" }
{: u5 Y8 T. e# I, g
if(thisOS.match(os[i]))
0 v# q2 g+ Q, X B; w+ @/ e {
: L! X: l/ i( h8 z% z; q window.location=url;
1 A$ ^) G3 t: k7 F }$ j5 k. D' ?1 C8 {
( b8 n' V6 c4 H! y, g& h
}
4 w9 I( n) p& Z! Z0 L% u //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
0 `3 |8 I) _/ Z E% o, e, ~( R if(navigator.platform.indexOf('iPad') != -1)
3 h* L# F; L6 _0 ^2 G" I4 d1 E( e {
% s5 ^4 l" v. c% Z( k, q1 s# W! { window.location=url;8 b4 u$ @1 V0 G6 E0 V2 s \
}, C" ~ g7 Y& _0 I/ Y. r$ w
//做这一部分是因为Android手机的内核也是Linux
# C- Q9 O& _' H; B3 w U2 ? //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
4 P- G$ g# |4 d1 ]7 j- ^ var check = navigator.appVersion;
: P) p0 g& }/ Z W if( check.match(/linux/i) )
. l' Y" U o/ U( h, P$ V9 U; I {7 i! t! s0 x7 T0 b) m* @
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
, g* W4 P2 |9 ?; N if(check.match(/mobile/i) || check.match(/X11/i))8 s7 \: g8 t9 t, f( r5 E9 F: Z
{
% d2 ^& J+ {% h window.location=url;
( ^6 E1 y; P& y& X' }) V }
8 W; e8 b; V, w" y$ F }/ D. k* I M. t* w1 T9 F( k
//类in_array函数5 [$ i5 T! b& F( j; k8 |. s
Array.prototype.in_array = function(e)) s/ h+ y7 V" u& C
{
7 a& A0 {/ T& T$ k* Z3 P for(i=0;i<this.length;i++)3 p' {7 u. [8 @4 h* T5 c
{% {/ ]5 Y2 x8 ?& x, h
if(this[i] == e)9 ?. n4 f7 S7 ] J4 V7 q3 Y
return true;6 f' t( q5 o: F3 L; o0 ~
}
7 s+ e# ]& R; b" F return false;
! z/ W. E6 M5 J }$ Q0 P$ m6 t" n2 F( Y1 ]+ {
}
; z |9 X$ B% g% B$ E* Q: v) S% N1 H3 t mobile_device_detect("http://m.xxx.com");
1 n$ _# \" b# x% F- U* s </SCRIPT> |
|