|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。+ j3 ]( h' D) p4 N
+ s; ~) K. r3 d _# q7 u<SCRIPT LANGUAGE="JavaScript">
" ]# S* q$ {0 e6 U4 z function mobile_device_detect(url)
! D7 x$ f/ C* O; ^ {7 A6 x! L8 ?/ M0 D$ B: N) n1 C/ L
var thisOS=navigator.platform;% v" b% N4 j. T' l4 {! M* M5 n: R z
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 E% [% `; C& q) e. Q F$ Z- R
for(var i=0;i<os.length;i++)
" u; N: q, [" |5 U( d' J) C* |. H {: p. _+ Z+ Q. I2 A
if(thisOS.match(os[i]))
. a1 B' i7 T' q: V* e3 ?* @ { 7 Q, r7 _7 Z z5 Z; N+ v. n
window.location=url;
! W: S0 R4 h1 p4 s n: f }3 ]+ P+ [ {2 H3 J8 r
- g4 |. _5 G# ?5 z3 ~
}
. Q' R' B8 G/ @1 V2 W //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认: Y1 t& H) D; c) }
if(navigator.platform.indexOf('iPad') != -1)
$ ?3 F: Y6 ?% i0 Z4 f {
: S' P9 ]9 v+ _ window.location=url;
7 L; \- m2 ` I" u: D' a9 m h }) q( X4 x% j ]- n* g
//做这一部分是因为Android手机的内核也是Linux. ?; t. p1 o: |
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断; K3 S. r- S8 T; v2 Z# y
var check = navigator.appVersion;
7 ~- g2 K- B. O; u/ I# G) G# p# j if( check.match(/linux/i) )% m) r6 |/ d4 ?$ X r- J& M
{) ^, g4 h h& Y/ p
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
" b% S- _- e9 i# D- Z' h3 V2 X if(check.match(/mobile/i) || check.match(/X11/i))
8 Y9 t2 Z9 p- \( g9 \- C) J {
" |5 A, S+ H' R1 K& U0 O5 k* F6 V window.location=url;' |9 O5 P* t5 p6 D
} % o; d0 z2 B, n7 B
}' ]# `) p5 p8 K& z1 Z' b
//类in_array函数
$ a' ?7 V4 O% n! F Array.prototype.in_array = function(e)
* x& ^. N( {3 x/ ^& W4 K' G {
- g4 k1 q& o5 E! F2 l0 f4 j& j$ u) @: n for(i=0;i<this.length;i++)
9 c3 b0 h* H2 M3 q/ M {$ T6 O$ h* o% b/ N" [, a5 r
if(this[i] == e)) g8 y9 l) ~$ r, b
return true;0 }5 c7 W. G- ] \+ w/ c
}
! A3 N7 \5 K$ c: E. T return false;, ^( y, U% D3 q- W
}
4 ]* L1 q) ^" J4 L }
6 k+ ~( K* o! }2 P) o mobile_device_detect("http://m.xxx.com");
% A2 x, v0 I% F. o0 O9 }% P </SCRIPT> |
|