|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
2 u6 U* i" u) [- c0 r6 b, N4 h- u% \
<SCRIPT LANGUAGE="JavaScript">
) x* N7 K* y! N# [' i function mobile_device_detect(url)
/ k; f0 K H/ n2 I. a1 U {5 Z; H5 z v5 ^5 @2 w8 \
var thisOS=navigator.platform;1 t( _8 P' u% o
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
! D# e# S- Z. R/ F5 q5 G for(var i=0;i<os.length;i++)
9 t. Y+ w" T4 Y! }/ b# q {
4 o3 M+ z) m) W" |9 q5 t7 U3 h } if(thisOS.match(os[i]))- w" }: j# i2 ~0 X* g4 W" r/ n
{
5 g" X4 a8 G* Q. v' Z; r5 _ window.location=url;: ^& g9 j o( B# |1 M5 `4 H
}
& E3 `; E( W4 c6 I' a0 G
4 d" Y! U: Y/ C! h& t }
' b( k$ c/ _" `" E G0 x: I //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
/ n' Y1 R' n. e( N3 T/ v. h if(navigator.platform.indexOf('iPad') != -1)
- C* ?1 t- B* H* v0 b6 H. S3 P* Y {) V, J4 I( H) G, C. \
window.location=url;
' Z3 }" z) `/ J1 { }
% @" x( b3 i( x% ^ //做这一部分是因为Android手机的内核也是Linux% \% B+ W' B- J: O+ `- C# y
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
6 C/ U7 k1 X! }/ s& i var check = navigator.appVersion;
/ x1 g" G# k+ l if( check.match(/linux/i) )& \. H+ F- F" J9 q# R5 T
{
2 @7 ?& ]* Y* H& \( } //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件# { S7 Q4 C" q( y
if(check.match(/mobile/i) || check.match(/X11/i))
: e1 Y" U/ D7 ]0 q, t {9 J7 s4 O5 U- m/ ^
window.location=url;
3 W8 ]' E0 F' V0 d$ R/ } }
) \( t/ U2 {8 A* F% y }
+ `$ X( j m( P" ^ //类in_array函数
/ d0 Y/ d0 @$ ^ Array.prototype.in_array = function(e)
5 n4 _6 p( l( u2 T/ D) o0 B0 i: m u {6 g: _, u H9 V" Q% u( d
for(i=0;i<this.length;i++)6 V: n+ u! ]. X# d, I
{
" p5 o9 t" I. ]% v9 L- q, K5 P if(this[i] == e)! N& l/ P+ e5 \* S" ~; v6 i
return true;/ {# q8 x) C: t6 Z
}
' v5 ]9 h4 T8 S3 G return false;, {8 J/ Y8 W- j* M, @+ T
}7 |3 e& W: Q2 _4 y
}
5 \# H' w- h4 u% o0 |( K! v% O mobile_device_detect("http://m.xxx.com");% ^9 n7 G: G+ W2 \) y+ x
</SCRIPT> |
|