|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
7 {( x, ~1 t, x! E; F6 o5 N$ @: G4 ~3 U: \
<SCRIPT LANGUAGE="JavaScript">+ e; N5 `( B7 Z9 w X8 }0 l6 P
function mobile_device_detect(url)
2 h! o, |: P s0 D6 V {
" l+ p* @7 S. ]' B1 X var thisOS=navigator.platform;
" G! J3 C* y- b/ O% \9 n$ \' g var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");' m/ p0 M- C A1 W5 R. D
for(var i=0;i<os.length;i++)& i3 h5 s) @' ?/ n+ b2 d- E
{
4 q2 d( L) ?$ M* Q2 H4 ~5 }+ Z if(thisOS.match(os[i]))8 s+ ?6 R1 s9 k6 u6 f. a
{
$ U( T9 _8 \$ e( y2 _ window.location=url;
' G# m! l. d; ^3 G r } R+ s3 Q: _! o+ |3 n, H9 W
$ P1 t/ ?* q8 ^/ `* n; r; N/ l
}- H/ ]4 c9 d5 K
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认9 ~; ?' q$ y4 D2 B2 C( i
if(navigator.platform.indexOf('iPad') != -1)' z4 H4 z, B+ M% Y; E
{0 W7 c- ^/ T* V* [5 i) P: o0 }# Q
window.location=url;
^2 c, B/ y9 ~( I4 Q }
( j) B1 e# p) V. X" u //做这一部分是因为Android手机的内核也是Linux2 L" f4 o4 e: k5 K$ i, J
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断, M& L8 A; J4 s( p2 o4 o8 G
var check = navigator.appVersion;- @2 J9 c* f0 K# G+ ?; J
if( check.match(/linux/i) )
- R" d4 v! ?6 h' R B& g+ q {- y/ Z, K! u# @; G B
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件7 n. G3 O! z2 O* I8 l3 Y0 c
if(check.match(/mobile/i) || check.match(/X11/i)); g. k4 @. e v2 ?- E2 O. \* H. Z
{$ Q. u0 K1 v5 q1 _: r
window.location=url;
) o7 ?2 q+ v$ B+ i4 R } 2 U# l* H! o) c
}- V1 U# v- l8 }
//类in_array函数( ~( c% X/ e5 {9 g
Array.prototype.in_array = function(e)
! N4 Q) ~: _2 z, p' l {
( N- M) w6 ^2 a! O2 z; _ for(i=0;i<this.length;i++)
' E& }1 H5 J) z- X1 H {
$ Q* U2 N3 Y* w0 |2 i! M if(this[i] == e)
( C% I# _' ?7 X4 I: | return true;7 B2 h/ M5 O% f& `; g
}
8 d5 B: g H9 t( ?$ p return false;
. S( b8 S; C% `9 C" V( D }
, ~( ]5 F* \( T* w3 H+ w% ~, x }
6 x+ y2 z+ g' @& T: B mobile_device_detect("http://m.xxx.com");
) m0 z, x" n' ^2 w$ j! B; i </SCRIPT> |
|