|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
# Z$ h/ ?/ i2 R( E
4 @" j1 E4 b' G, s0 \- b, ]<SCRIPT LANGUAGE="JavaScript">7 D5 }8 L! N( t
function mobile_device_detect(url)+ q1 S2 h) y6 m" E
{" r: X( O+ w+ [
var thisOS=navigator.platform;
5 r: S$ [- A- N& A var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
* i5 r# r7 Q! Z. i' o for(var i=0;i<os.length;i++)
; q" ~' v/ m& Q! g3 E" {6 V {
% M+ r9 ~( t9 a6 c8 |" Y if(thisOS.match(os[i]))) W# ]- }4 Z D
{
0 A9 j* f. e: c, A window.location=url;
- U1 w( Y! ?; ] }$ [2 _& o' Z3 }5 U; N7 J
( n0 B& N3 w( b$ K }
) D) s% [" P# R$ l8 Q; I1 W/ l7 E& V7 O //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
% V" Z- r2 u% y) D/ R. G5 v$ M: P if(navigator.platform.indexOf('iPad') != -1)- |1 _ b- k: @5 y9 |; N) t
{( S, C; T4 L9 b; i. t* p
window.location=url;% u1 O4 _* H2 o( _% L
}
) u9 o, s1 B1 c2 c" u5 i* E" i' g //做这一部分是因为Android手机的内核也是Linux
) \3 i; \7 L) j. R0 R, J //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
5 }2 O Z: F/ k3 t- i" @ var check = navigator.appVersion;
# |7 N8 `# X& M* d, Q1 J if( check.match(/linux/i) )5 d% E; N0 E4 r9 M8 h) V! Y' Q" ^1 o
{
# J$ P0 _3 z8 k# b7 ] //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件9 J/ ^! V# b- Y) A/ Y8 p* V
if(check.match(/mobile/i) || check.match(/X11/i))
0 V/ \7 @2 d" V! k* N {% T" M# B. q) V# K) q# W C
window.location=url;
: y, j$ A- H( E9 D+ {4 _ }
- _9 s; ?( H# x* N }, x- @( S& a: }& B o
//类in_array函数, R5 m2 i/ h/ c: e
Array.prototype.in_array = function(e)% Z+ r) Q& h7 Y8 `4 | y
{
5 j( G k& w P3 C9 [ for(i=0;i<this.length;i++)8 Q6 t/ d% P2 d( g
{- G5 r( e6 [# F* Z6 M
if(this[i] == e)
" b" R4 F4 @4 R, j: N2 I1 l* i return true;9 h% g* I# B3 `1 E$ i8 C6 P
}
( w* Z, ?9 ^4 g# ?/ A return false;7 E( m% q2 s+ k0 b3 R* |! u
}3 b9 m3 O) |0 e5 s( Z/ u
}
2 z! h& n+ E- u1 k mobile_device_detect("http://m.xxx.com");
; q( _; I8 f$ a" v( n; F# y, z) w </SCRIPT> |
|