|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
9 t1 @, ~+ i0 R) d* M# a7 B5 m) A) ?, c* u. t, M
<SCRIPT LANGUAGE="JavaScript">
! Y6 [/ c( h/ d% d function mobile_device_detect(url)7 d* j! `8 i0 _* D9 H8 `7 d( H& K+ v
{: X+ M2 D S3 [1 m5 _
var thisOS=navigator.platform;
* l! G4 S$ K3 B# a4 I/ I7 B var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
$ [* b9 f$ {9 b; m S for(var i=0;i<os.length;i++)2 b) K* @' K+ V
{7 ?) t8 V' ^4 d2 [+ a$ Y% [" f
if(thisOS.match(os[i]))# q( v$ [% Z8 F& {# f) n
{ % K* |; V8 ]1 b& m# C( D
window.location=url; O5 Z1 w' f- @
}
0 I @8 A. A& a5 z, P& v4 J 8 ]1 L+ W) o, s' ~5 W0 B+ z r
}
) S% t2 p: y3 e# M, r //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
- S! q8 g& s2 W" _* h# @+ N G. U if(navigator.platform.indexOf('iPad') != -1)1 ^: v! c) O$ s9 Z: ~
{1 N' |( v5 i0 _% c' g- _
window.location=url;' M: o# p }* [; z `
}
; S) c2 a1 [1 L( T //做这一部分是因为Android手机的内核也是Linux
# @) K Y' t h; p' U7 D //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断# l8 W! |; g* z6 W
var check = navigator.appVersion;
- W2 T6 A* Q: H! A if( check.match(/linux/i) )! `" }2 S+ J& J e9 a. I7 u
{/ l; Z) Z1 E# S3 O% x1 S
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件4 o$ L% o' W& T" I, O8 }
if(check.match(/mobile/i) || check.match(/X11/i))" I9 S T( L0 X+ L/ Z
{* E; ]" R$ e' `# \
window.location=url;
; y# N' }# M3 u: \9 ~ }
# ?4 s$ \2 F3 O% T9 N7 A }
# r: q& D! ]$ H6 w //类in_array函数
- a: `$ C' C: z! ^ p" Z Array.prototype.in_array = function(e)
( X5 b# X/ b- j6 G: z- n6 f {2 ]" U0 m* B$ O6 m
for(i=0;i<this.length;i++)
( z: t" X0 G" | ^% U& I0 k {. {1 _0 E, V, [) X! L
if(this[i] == e)
1 n# r; U& B5 E5 B! J# ]. ]- C5 u8 P7 z" P return true;
* K ^" x( k3 _1 ?: Y$ `+ M }
8 S# g, F; T- _) s; J4 D( R return false;* q' P9 u$ z. x: e; Z
}
. D+ n* ~' F% b2 o } ; s0 {# G8 t5 p, ~9 ^0 G
mobile_device_detect("http://m.xxx.com");
3 j+ C0 s, T2 c% z+ T6 w </SCRIPT> |
|