|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
, g3 l1 D( b$ d* w
1 L2 ~- H" o% f7 w0 y<SCRIPT LANGUAGE="JavaScript">
5 r/ D1 W6 J4 O; P function mobile_device_detect(url)" ^4 c8 w: B- b; T/ k! I1 W0 d
{
7 S' `5 }" D9 b4 C" y' Y var thisOS=navigator.platform; X) i8 a" e7 X8 S$ w9 H
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
) a9 v: P c4 } L! V" N8 b+ N for(var i=0;i<os.length;i++)
8 u. Y: K" j9 p) ^/ B \1 J {
# F& ]8 Y4 R6 } if(thisOS.match(os[i]))1 x! P: H0 n, g& S- ?5 g1 L
{ 3 I; t0 W- b9 T. w- x5 ~; W) ~2 u
window.location=url;
/ f1 ^* o$ z% y6 n3 _9 Q }
% `- X' s% T7 u4 g! r . \3 `3 s! D4 [9 x8 P% `% J; D
}+ u3 }' [0 |! t' z. w, h
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认5 S& ?! e4 @* R% ^+ S
if(navigator.platform.indexOf('iPad') != -1)6 _: q* E9 ?- n7 j3 o: C
{5 |+ O% M2 s/ S* v
window.location=url;
. H. { U3 d% ?, L8 v+ V! C! I: L+ h }
$ E; B0 {) O8 ~3 z //做这一部分是因为Android手机的内核也是Linux( P% k# F- p4 N. [/ O/ K
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断: \ X) O% h$ R/ F
var check = navigator.appVersion;
2 b- {6 @! s5 J' J if( check.match(/linux/i) )
" k1 Q( ? }$ D% A6 D3 X* V {. n) U$ E! `/ g6 j% P- {5 W8 w
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件2 B, c8 ?0 X( R8 I5 x. R! `" [ S
if(check.match(/mobile/i) || check.match(/X11/i))
" ~( P y" x V4 a* B7 _ {7 ~: A7 d8 _8 F; w
window.location=url;$ o& y/ e! N' E* }3 g [
}
0 A) y/ y3 R2 L/ s }
2 {2 W8 t5 v6 K( E //类in_array函数
* t2 F4 b, P G0 L# S: v Array.prototype.in_array = function(e)
' o i: _6 _+ c4 P* M {3 `/ k* \) p, c, @0 V1 V
for(i=0;i<this.length;i++)+ I2 Z* I1 U. `6 u; {8 h7 l6 Q: G' y
{8 d1 @9 C7 ^6 l/ O1 `1 z; y. v9 |
if(this[i] == e)5 `- z( a% Y3 [% ^- @
return true;6 } I- P. l9 L5 m9 m
}
/ G1 A5 P8 ^5 T/ B7 h6 ]* ~ return false;
9 x d& c; k- ~% } }
' ]. y2 o3 o. _ } " p0 `$ O1 c4 }. _
mobile_device_detect("http://m.xxx.com");
& l! \) |- p2 x0 c7 u1 X. X </SCRIPT> |
|