|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
: m0 Y! w* Y0 P, n% u" u0 K i# G/ W9 A8 t
<SCRIPT LANGUAGE="JavaScript">+ i! ]9 A+ J# L" O4 Y
function mobile_device_detect(url)
9 o- P9 c! h! [9 g% s. e9 K3 T2 q4 k1 x {
8 B s! D. q0 u' I, M3 C) G) ] var thisOS=navigator.platform;2 K0 x' L& l, W4 G4 _( x+ K
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");: G2 S: |# A& Y0 ]/ y" I# j
for(var i=0;i<os.length;i++)2 x, M' d6 d, e/ H# n0 D$ @
{
/ F# I+ ?0 Y; e if(thisOS.match(os[i]))
3 Y* X0 F+ A! Y- { {
6 I" T7 {( y& y5 D6 J) W/ r; [ window.location=url;
( d- n' O: @; c* Z3 y }
2 c$ K7 u; d g& p$ e6 K
5 Y3 E9 n$ `6 b4 p& Y6 ^+ T# U5 k }0 G9 q) [; T$ b3 v2 H5 [$ |6 g6 K
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认2 L" R4 z* o) d" F# s; a
if(navigator.platform.indexOf('iPad') != -1)
; g) }: M* A2 D1 ?# m$ ~ y* Z {
( [, a: m3 p: ], C" o! Z window.location=url;7 I d3 i- x' q+ U" o4 l& _2 ?8 k% O
}
/ _9 J% |' U% _# B+ I, F& s& Q! B: Q //做这一部分是因为Android手机的内核也是Linux- N" Y2 V5 h5 ?5 L
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
( a0 ^) \" X/ m var check = navigator.appVersion;. w" W* o1 s8 F& D
if( check.match(/linux/i) )
( A+ G* T! j- K1 L3 O+ z {
8 e q y; j9 C8 K0 _! [ //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件# ? N! n1 m5 c1 O
if(check.match(/mobile/i) || check.match(/X11/i))
0 \8 e$ |/ R) Y( ]8 w4 Z {
: Q$ }( c9 e. ]. x: `, z6 k D4 O window.location=url;- a' r) X. d/ I0 v) [; C x. e
} ! A: u) H# ^ [, r) f+ ], V
}
4 b. X \; Z6 T& X //类in_array函数3 E2 g; Z: A7 j% g" ~6 m" E
Array.prototype.in_array = function(e)
. J: z( O7 n- m. w {, H C+ E2 O% g
for(i=0;i<this.length;i++)1 Z% J' O) m6 D) l4 i# k: V
{8 {3 h1 o0 }3 Q- _& J" O
if(this[i] == e)/ n: G7 H; q" e9 O
return true;$ O5 y. P b4 i; H+ X
}
. p% L' v- y0 V% K& M$ v' L return false;1 E. o2 {8 j k
}( D! f' K- K u& T
}
- @8 F/ w& n* u mobile_device_detect("http://m.xxx.com");
7 u4 u* c+ \2 V$ l9 ^ V3 J1 x </SCRIPT> |
|