|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
% o" u5 F1 u! [$ W' J& v) `' {
! a- j. B. t: |( |. \2 y; C6 E<SCRIPT LANGUAGE="JavaScript">
/ F$ P1 i/ L* M2 A! p7 G9 l function mobile_device_detect(url)+ E; Q/ ^! L2 @6 K
{6 G! x+ ^* W! _7 J9 Y6 v
var thisOS=navigator.platform;0 D9 `; k9 Y4 p, q3 j
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
2 x9 R" @! ?' l0 a* H for(var i=0;i<os.length;i++). P6 `# ~1 l' m( h3 N& A& t
{: a! b' F* f2 a- A% f# m
if(thisOS.match(os[i]))
1 ?4 _/ N1 ~) B' j { 1 V! n9 t: W, e+ u( [
window.location=url;* y. K" { v. [/ V
}4 @9 d. V6 s9 T% B
7 |- L' N2 `3 _& ?( ]
}1 y8 [- s+ ?6 }; G) s% u0 p R7 e
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
, ^& j1 M* T/ J( ^ if(navigator.platform.indexOf('iPad') != -1)
) o" B6 m' k4 g5 m. b7 M2 ?; R {2 ]; U9 b- u: M4 w# K+ q
window.location=url;3 O) Q. t' V/ o/ R. e+ ?3 B: y2 u
}
A8 r V1 q3 `9 k //做这一部分是因为Android手机的内核也是Linux
# Y+ d4 H2 O- h //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断' j* o# R$ P- z0 a1 e) G. B9 Y
var check = navigator.appVersion;
, }; i* W& }3 k4 m6 G, p# k$ K, t if( check.match(/linux/i) )
2 g# P( x( \5 S {
& g) \& O/ ]8 N x0 k: X1 ? //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
1 o0 {& I8 Y% `8 [ if(check.match(/mobile/i) || check.match(/X11/i))
& Y- }2 Q7 M' g6 K, n# {( _1 V. { {
9 o( e) F( T# v7 U window.location=url;5 y- @ U* h- `
} 9 d2 v% v/ K9 Z+ w5 K; H
}
& w2 p3 z) p @$ o1 g! h/ P0 |; v& d //类in_array函数
( @2 x' K e1 x8 L- t Array.prototype.in_array = function(e)3 z R! }" Z! Y4 D# c
{9 l8 } s# T, q) W* w
for(i=0;i<this.length;i++), y2 _! O2 t$ S* ?' b
{
" ?' J. Y6 h) q3 r if(this[i] == e)' b1 d. n h) q, `( s
return true;
$ ]% S) z3 |7 N6 } }
! W) U! C& W3 E return false;
$ ]/ @& ]* B# y+ ]) a }
6 Q9 k- E/ |; E7 ^ } ' M) N ]/ s9 ^4 f
mobile_device_detect("http://m.xxx.com");
W: B+ K* S' t4 j B6 [/ X: I+ p9 \1 Z </SCRIPT> |
|