|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。 @" e- [+ I8 f& U( ~
" }. B, T3 y: v* H5 F
<SCRIPT LANGUAGE="JavaScript">5 t ^$ w0 R1 x' |
function mobile_device_detect(url)1 Q2 K! G G. A: ^. f
{9 w$ Q3 D* K! K5 h& W* I
var thisOS=navigator.platform;
7 r; f5 r: a0 k- s* E$ I$ 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");
4 A9 o7 H6 r! F; b for(var i=0;i<os.length;i++)6 a& M1 A/ n, p
{
0 h) G0 d2 }5 C/ f; j6 |. J: S: E if(thisOS.match(os[i]))
\% E. k+ _4 F% Z/ @' W1 Y; t$ A9 ]* T {
: J8 I/ g. Z6 _) D: U window.location=url;
& d6 @/ u+ O) x; r# K* i' w0 s }8 B' k8 K5 I0 `2 c c6 n7 t, n- t
) [4 ]/ L4 M! ^) ^
}8 g& h) ]. c: B2 Y `) w
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认2 \; |1 r5 u2 \' p- u
if(navigator.platform.indexOf('iPad') != -1)
+ W" N* d+ T! z {
, a) s$ U" l" n5 ?$ A6 _ window.location=url;
7 d* `$ e" T9 @# ~' q& J) W }( A. |% k, X" \
//做这一部分是因为Android手机的内核也是Linux4 b* M) @; Q. F4 t, _
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
) o5 F" Y' u9 p4 o ~, D9 D var check = navigator.appVersion;
2 g# B8 q' x/ t4 @ if( check.match(/linux/i) )
$ P' ?9 P5 n% _0 ~7 d3 k {2 f; |4 k4 |7 t- s" Q
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
4 s8 C) v& O- D$ | if(check.match(/mobile/i) || check.match(/X11/i))
1 L, E$ o. Z3 D/ \ {
2 Z; J7 W/ B2 B }7 F window.location=url;( p( E% }& s5 ]6 Q5 w6 ]
}
$ H! q" m; P. y2 x" J) h }
- \+ I, _* y: n$ e0 Q //类in_array函数
) E2 j7 b I$ X: d+ \ Array.prototype.in_array = function(e)' Q: d( o, f& V) A! f
{
: O2 Z- j/ n0 x- ^6 u5 l5 y2 ? for(i=0;i<this.length;i++)
( @; l& K) L2 f+ R- q3 R$ y {
9 Z; m' x% g$ ^ if(this[i] == e)% e8 i( n. X& ]# G6 E$ F1 ]6 V
return true;
% Y. H1 T1 X$ p. w }/ B6 T( B! ?: G; t* \
return false;* ]; Y" Y( s& g0 |0 i5 o
}
1 |2 _" H& B5 {3 B } 1 G S' S, }7 y% c! }
mobile_device_detect("http://m.xxx.com");
" w! W6 h" o9 v; ^2 @% K1 ]3 S </SCRIPT> |
|