|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。2 _3 Z3 o! y+ ~1 `% E' l
: P$ v) s; S* @7 F7 y, {! R5 P7 K
<SCRIPT LANGUAGE="JavaScript">
3 Q! ^( q: y' P3 @* n$ e function mobile_device_detect(url)
- s% j9 f0 t: q$ u8 A, z {
5 N! s6 q* m+ A6 }2 v, t var thisOS=navigator.platform;
- V; Q0 K8 a& V0 F# `1 \% L var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");- |$ [3 C/ u$ q( L8 R' I
for(var i=0;i<os.length;i++)
7 }% y& ]& [' Y {+ _6 w; G& r P. s
if(thisOS.match(os[i]))
, `5 |" o5 F/ c' _" W/ d% t! \2 _7 } { : q( X5 C$ k$ _- | ?9 m
window.location=url;0 o7 Z: x, x- B N; ^6 Z3 A
}
8 Z8 X3 L! ?0 I6 E! p. s ' {, Q8 Y# ~! z+ _, q. v
}
5 Z! X1 w/ \5 k3 m //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
5 s: S) U0 `% c W+ G1 Z4 Z if(navigator.platform.indexOf('iPad') != -1)2 l: {& ~3 D- ]/ N! C
{
# {' i2 m3 o3 E window.location=url;
+ A* N) @1 C6 f7 C4 ]: c! U }
$ A# j" R$ f/ {& B. g' f0 a //做这一部分是因为Android手机的内核也是Linux, _) _2 K5 f# v- k6 G, b$ E3 u" V
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断/ U3 A$ g2 G0 I$ |( J. C) _
var check = navigator.appVersion;
. v) l: P# U, U! }% t if( check.match(/linux/i) )! e0 V1 s: U$ D/ R/ E
{% d: D! J0 ^. n
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
% K* f! C2 r; R9 P; J if(check.match(/mobile/i) || check.match(/X11/i))+ u+ d/ u# o7 G+ q" J
{
- ~# f5 p0 [' ]6 | x0 R$ \ window.location=url;
$ ~5 ^$ b+ g8 ^4 W0 [ } 8 ]; \) I8 {' }2 x$ g& [7 h4 J
}2 d- z% ?7 j/ x# s& H. F
//类in_array函数 {8 [' z$ \: d! f. t
Array.prototype.in_array = function(e)
9 D; y) Q6 i9 \- p5 ^7 ?8 d {
1 Z2 t4 G: _: O$ ? k- Y for(i=0;i<this.length;i++)
5 { ?5 i) B/ B5 v/ K a {
# O; n3 l: I J; Y if(this[i] == e)
6 A* z. R$ K6 l' o3 i, }# l return true;
' X; I# `% H3 O' m$ K P }, m: [4 ], h1 }" d4 i0 g0 B. u5 S( U
return false;
+ y! K8 [, W5 G. n }) F! e# I b9 R; R" o; D
}
7 c5 G7 B& _; P! W" p0 O+ u& L mobile_device_detect("http://m.xxx.com");
7 \5 F$ J4 Z4 N" x3 q% K4 A; _$ i3 | </SCRIPT> |
|