|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
- }( r8 C$ |. V& j0 h% v
' M% H$ R( f! \6 ?. w9 i+ x& E<SCRIPT LANGUAGE="JavaScript">/ w& s0 W/ V. a# t
function mobile_device_detect(url): t0 j" t- u+ d1 _4 V" [
{
# x5 k! r/ \* O9 [ var thisOS=navigator.platform;
. `9 X' i! y/ E1 K var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");$ ^" A* r) z, |
for(var i=0;i<os.length;i++)
- q, y* h% s/ X5 e5 D( s0 o {
: q, O& M+ v/ E: C( w# X( @ if(thisOS.match(os[i]))
c: i" T# }2 s4 `5 N# e V" F {
5 |/ Z' p8 }% ^: w( d8 \1 F window.location=url;$ X# Q7 J8 L* |$ y2 e! }8 a
}
0 {5 A1 ?' S h( A # g4 G: d1 M, a. i2 t
}0 q( u- W; G- F5 z9 {. M$ l
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
" L- @/ r: P0 }4 w5 M* M if(navigator.platform.indexOf('iPad') != -1)( q2 {0 K$ h) s
{' H: p5 h: F' z9 j9 y0 W s5 K
window.location=url; j7 p! F! z2 V" ^& C' Q
}
. t" e9 b7 a8 |: V3 q/ @& @ @7 e& \ //做这一部分是因为Android手机的内核也是Linux
- m! m8 |8 u! ?2 U* C4 N# k //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
( d+ H% o& Y# g; ~. z' n var check = navigator.appVersion;
# p% f, D$ P+ V if( check.match(/linux/i) )
% y% s& f& K+ ]7 V8 `$ p {1 Z% k' H9 `. C. Q' W6 |8 |
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件 `' M7 e! R) G4 }' R
if(check.match(/mobile/i) || check.match(/X11/i))6 _. g+ G0 Z( x; D+ Q; g
{
4 ]2 J% }% r9 j2 n2 Q window.location=url;
W/ T" N: d9 g: P- s4 P' z' e }
6 ]- b' `" ?) I* q }$ J- ^: S# U& b# g% k& ?) q
//类in_array函数
# U7 F2 `8 L w5 y4 B, }" E Array.prototype.in_array = function(e), Y; v0 ~/ S* ~1 N
{
! j [: f0 b! ~ for(i=0;i<this.length;i++)( H4 Z5 N8 e8 A8 f2 y0 R7 k0 Y
{
8 g: l+ n6 m6 W: g& r; \3 K if(this[i] == e)! l' [% s" s ^( |# Y& U4 h1 b/ @
return true;% p2 s5 z! x8 n9 m+ p( t
}* j* e- r# K$ b/ b
return false;
. x0 Z/ u2 L+ w, _! `4 O# `/ ^ }
3 {4 t0 c/ E) o* ?" e3 `! T# j } + E6 f1 L3 u8 }0 i; W6 W: e
mobile_device_detect("http://m.xxx.com");
0 Q3 E6 _% w4 I8 B/ E; |6 K </SCRIPT> |
|