|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
/ I. F# ^' ~6 P: @* b& Z
+ N7 B0 b$ G) g, Y<SCRIPT LANGUAGE="JavaScript">7 s8 g8 m4 ]. J5 x9 B/ [ p
function mobile_device_detect(url)
6 A$ ^' T% Y+ a* c+ q {
8 S( W L! c8 t. P# Q/ ^ var thisOS=navigator.platform;
, E& ^% `1 }, U- J6 W. z) L var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");0 [- W/ T( n5 j7 I. L
for(var i=0;i<os.length;i++)( L, g2 c$ A, o+ `1 q
{
: |6 c- u/ `" J4 i# r0 _ if(thisOS.match(os[i]))
% i, W. T- f' l, E( f' p% B. j { & e B$ l! M/ ^ D5 L( i
window.location=url;
7 K6 ^/ @5 K; K, o1 J( x* i1 c. L }
* b* p3 o9 T! s& E# s; x , _$ e5 Y! j( @# K
}' T" P. B, [6 u/ m, [+ t: l! @% O4 \
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
% `, k5 P# l! ?" V; v if(navigator.platform.indexOf('iPad') != -1)
) O4 d5 w2 c: W6 n {
+ j1 [' N2 \9 J, m0 [& C window.location=url;
; T+ e( _) Y ~( a1 g8 Y, x# e }
" K% ^* X+ W. G2 O( g- T0 r' | //做这一部分是因为Android手机的内核也是Linux0 _9 Y$ u0 y! f( ?( f5 s: _& p' R
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
; R5 j r& X7 o/ h v7 C var check = navigator.appVersion;7 r. \5 v5 f% H( V6 w/ a4 m
if( check.match(/linux/i) ); `5 z% t5 e( ^
{
# [9 T. o+ P" R: X7 ^! S //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件$ C" E" I& K: W. k" v5 t: G
if(check.match(/mobile/i) || check.match(/X11/i))
p+ ?9 P/ s4 ?/ ^) h { }- Q& ^5 g0 O1 @
window.location=url;( ]$ ~5 U0 k& k$ B( t& L! v# i9 t
}
0 w% b, a: j5 [4 ~: E }) u7 I5 @( {, Z$ P5 L6 n p
//类in_array函数2 G* N! z( ~. \5 D w
Array.prototype.in_array = function(e)7 _+ M: n/ X% X/ u, ~; {/ M8 R
{: R- X" w6 G. `+ c' N
for(i=0;i<this.length;i++)
5 O$ F1 {/ V8 T( e7 b8 W {
+ s% b3 e( \# t; n3 t6 F5 b5 t if(this[i] == e)1 z W! m: g6 J6 r: T
return true;6 W6 u3 G% w" d$ h
}! t5 y4 y( N; F5 l" p- l
return false;5 Y* t2 k; n% e. [* F/ {8 S# D
}
. _. M( {9 q1 [+ O8 X$ c }
[. u" T/ i# R% j6 F) ? mobile_device_detect("http://m.xxx.com");+ M0 }% S9 _$ w3 Q
</SCRIPT> |
|