|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。# v6 {9 b8 s2 m
, g# s5 G8 l8 f7 |5 L) c<SCRIPT LANGUAGE="JavaScript">- s/ `7 V+ i' C I, m8 Z0 E
function mobile_device_detect(url)9 K; Z. ]! S1 f3 b N
{1 r& l! s0 @* V4 C: x
var thisOS=navigator.platform;
/ _7 O2 [! ` _8 k/ D, ?4 @5 u" D var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");9 U" ?4 T- A7 K* Y! s
for(var i=0;i<os.length;i++)! {7 p, e% ^( H5 {6 i! s
{
' m, y9 V) a( l3 h if(thisOS.match(os[i]))( m1 O+ h# C: y4 c) I- ^7 k1 V+ k
{ + b+ t# j8 M* z, f4 j, C8 Y; z6 N6 e
window.location=url;
) f5 g1 K4 l: O3 f }
9 ]8 {- M7 N' S& B) h1 P : r$ i1 V+ R: ^! d- t' W/ f
}
4 O; h8 q6 M2 r4 Y L5 ?7 p# s, l //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认' l! d, { z" F
if(navigator.platform.indexOf('iPad') != -1)) H# h3 m: \8 h4 M
{0 c2 [: y( `& Y! A# j$ W
window.location=url;5 d; {, F, e. r* W; h
}
. ~6 V- h1 _$ Z/ @ //做这一部分是因为Android手机的内核也是Linux
: i8 a# n& c0 y3 b3 Q4 g //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
& E: S+ `! E+ b. l! r1 \ var check = navigator.appVersion;
+ \) y7 P0 V# _* B7 r if( check.match(/linux/i) )
( e" s+ G/ S3 Z; M& Z {& x1 o" i( ^ J/ W; U& @; c
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
. {3 ]1 ]7 {) q b. Y if(check.match(/mobile/i) || check.match(/X11/i))0 O! m& `8 C, p
{& K: X6 Y% b" d* u7 C" G% c
window.location=url;8 z0 d, X/ t/ _, F
} + n t5 W, q# b
}) B, v% L# p" j9 q O/ q) h" M1 f
//类in_array函数
- j- R' \( s. U; r8 S Array.prototype.in_array = function(e)1 t% Q2 L+ S, _
{! m: e0 S0 K0 W2 [, b; A
for(i=0;i<this.length;i++)
5 k, o7 |# n8 @- \. @: X X' B {% J$ c2 v; g5 |6 e/ A8 ^
if(this[i] == e)
+ W. T9 e+ D% ^" Y return true;
8 \! E1 m" z% ~2 c }5 ^/ w. o6 X Y9 {# h! }( D
return false;
1 e" q6 N* z" W: U: ]8 T3 U. ]# l9 G }8 }' y! x% h7 {$ x
}
) t6 h, T# G Y3 e- _ mobile_device_detect("http://m.xxx.com");0 @, H$ k- i, {4 K
</SCRIPT> |
|