|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
# s3 q+ n/ {8 I5 m6 w& a
H0 F& P* s9 l/ o( J2 z: Z<SCRIPT LANGUAGE="JavaScript">
5 A5 @3 E6 K, A function mobile_device_detect(url)4 n6 q V$ Z, m$ Y' u2 i9 v
{
5 e" R% e" y3 ~ var thisOS=navigator.platform;* e9 W% C6 H1 N4 ~
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");8 ~& H, g2 C8 l) i, L" l0 S9 L! i
for(var i=0;i<os.length;i++)
0 u- E6 D9 J! d; w9 Y* G {
+ o$ h: c+ m+ e% k* x+ q if(thisOS.match(os[i])) R1 Q5 @% z# @& z
{
6 i9 D0 j4 R6 w4 }& T7 i& g window.location=url;
& v3 A8 O" X" Q0 G }- Y4 ]4 h$ }1 N
3 @/ i8 d% q2 ~% \* c0 v% }: p
}
+ S6 T+ Q8 u9 S/ o //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
3 a6 a! R0 \+ X2 [7 {0 V if(navigator.platform.indexOf('iPad') != -1)
! f5 h! c7 F* v! v5 s {; z; g2 L3 l5 ~4 M3 x& @- o
window.location=url;- q" I8 w- s+ M* _5 K" y
}
8 H5 F) _& K; a //做这一部分是因为Android手机的内核也是Linux
: r9 A+ ~# n5 f/ S5 c( i& K //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断! U- o9 e6 b+ K" o& ~
var check = navigator.appVersion;4 u" x0 p. |# b8 z" t
if( check.match(/linux/i) )6 h3 |( t2 D: Q: A7 z' Q
{
2 Y: D, i; J" \2 ^2 b6 G# f2 t //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件4 t6 T0 C/ Q8 `- O
if(check.match(/mobile/i) || check.match(/X11/i))9 f" D* ]8 W' H. g5 F7 x5 X j$ D: f" c
{
: d( y5 e+ N- W3 J" f- r/ ? window.location=url;
2 k5 y; j# M) v$ h: I9 h/ v$ T }
6 ]0 q( n3 n: }' |: M; W' Q }
$ c5 g R8 i7 f: X& }1 b2 w* A //类in_array函数
1 w. C7 O8 F# D4 a1 b" ?; t Array.prototype.in_array = function(e)
/ Y( i: @- \$ Z {
6 b. z( n; e5 }, V for(i=0;i<this.length;i++)
8 i. j; ?4 }$ R {5 w6 ~0 b9 v: q0 |9 l0 G1 s* X) x, U
if(this[i] == e)
7 @8 n$ Y( E. ?, o) g return true;
4 E: K+ \( k D+ l! Y }8 o8 C5 f) ?: {' h4 w
return false;
" ]' y0 |2 F9 W }- G0 S* ^$ J- O0 Z' B" \
}
. ~, X( W: G. y mobile_device_detect("http://m.xxx.com");
* }' d# f) B: U; |5 i. L/ e </SCRIPT> |
|