|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。8 h2 R. w) _: u6 x4 L9 Q; F: a
5 i8 h9 [3 \2 N( E" M
<SCRIPT LANGUAGE="JavaScript">; U4 b6 P. g( e4 A/ d
function mobile_device_detect(url)
) n" \1 l7 E* l/ w @. ] {9 z( I4 T4 b9 |% b3 T
var thisOS=navigator.platform;
8 B) f$ J) _( [ _; n& C2 W. \ var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");6 ~" y& I4 D6 t/ C) p$ l, Z- ~
for(var i=0;i<os.length;i++)7 _' H: v% y S* \- O) [- p5 z4 s
{
5 n7 N- i& u. A5 I% S if(thisOS.match(os[i]))
0 l! G+ p" _9 v8 ^ {
9 `& I7 S$ e( X" }$ C! m7 M window.location=url;
9 @* [9 k/ J. {+ P& Q9 d& [ }5 x1 r) p6 C2 ?3 R$ Y
' R0 [8 }, d" {: i }
1 m. I3 A2 Z @3 j( Y' Y //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认& ^+ W% C& d5 I, C7 S
if(navigator.platform.indexOf('iPad') != -1)
% h3 }+ \3 L2 I! ^/ ]2 q {: U% D3 ?+ e) v- T$ r7 Z
window.location=url; f! ^- G# X2 }0 @4 \, M4 {0 Y
}
9 W7 ]+ b* e ? //做这一部分是因为Android手机的内核也是Linux: W0 F( p. f# m" D) J
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断4 i& U! {' C( U1 a+ K, f' u( l
var check = navigator.appVersion;
/ s; O2 y4 a, c5 o% a' G if( check.match(/linux/i) )* t6 M. R* }( H& z1 r F6 o
{
N9 j- k$ E1 t$ L" M3 C# f: K //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件' h( {$ b- D; }
if(check.match(/mobile/i) || check.match(/X11/i))* y: ?+ `$ E; Z2 V
{2 y- }8 m4 P% i9 s1 O% r
window.location=url;
$ Y! E. `" P% ^ P }
$ x, I2 D$ A8 F1 F4 V7 M }9 G: y4 K$ Y7 v' B: `# j
//类in_array函数: j8 [! U: j+ T( d! F; m/ c
Array.prototype.in_array = function(e)+ C# Y! I5 l j5 H6 O( Y5 q
{
( o- w8 I9 A# j' t% Z for(i=0;i<this.length;i++)
" E: h3 ~. W! w* C' A) O/ Q0 _ {. Y% S( M/ V# |6 k) a# S
if(this[i] == e)1 e% V2 s- |' I/ b. b) W
return true;
_/ \2 d/ ]/ l }; a& ]3 ]- W# E
return false;8 s7 z4 b3 c# k8 Y+ e5 c2 j
}
1 w! F: i: }5 f" ^7 g } 2 D5 ~9 N' P" T
mobile_device_detect("http://m.xxx.com");9 A1 w& [; E, j5 g; N
</SCRIPT> |
|