|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
$ Y! x2 o5 p' m8 z7 q
9 S8 J: |* J: [( d' Z# I+ p<SCRIPT LANGUAGE="JavaScript">
, _2 H q. s# [8 `, R) R6 b function mobile_device_detect(url)& C7 |& R! q7 V7 X. h3 u% Q+ z; u
{
, n! L& A$ W/ D var thisOS=navigator.platform;0 k9 t3 A( O1 _1 _& ]/ @% n3 Z
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
) G8 b, e6 D! i: M! h; d& }5 [2 t- N for(var i=0;i<os.length;i++)$ s- e& d- Y* A' y
{+ K4 F3 t( K1 K% F; I7 V4 {8 E
if(thisOS.match(os[i]))
1 n0 y. r" Q8 b' I0 P! w+ A {
' H# I, h& ?1 l+ [/ J& l! c* d window.location=url;
) H6 D1 N6 g* b/ `" m% n* E- o }
$ E- r' d' ^' k" a ; j/ c1 p! `/ t: O& o+ x+ B* a2 H/ Y
}" w& r$ i! M: j9 Q" p7 u
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
7 ]- y& _2 d( j2 L1 g4 _# L: V if(navigator.platform.indexOf('iPad') != -1)
5 y/ z& @) F' I: e6 d& } {/ U, y# j! h6 Z V/ ]
window.location=url;
- N: `9 A D! o% P }
' u, e" I( Z d4 ^ //做这一部分是因为Android手机的内核也是Linux
) A5 {$ R( Y' K, j5 T //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断# u: U& x* _* U; v, }
var check = navigator.appVersion;
* p: z, A' B" n! `0 _* F- h% M4 e if( check.match(/linux/i) )
8 b* ]. h9 N5 @7 |. d0 g* E2 U+ _) m {- j) N# {( Q6 ^$ R* v
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
/ C9 X7 \& ~- Y1 h1 i7 d if(check.match(/mobile/i) || check.match(/X11/i))
9 e0 j, p) d2 b( K m {
: z1 Q2 x4 I& ^$ E. P- f window.location=url;6 Q9 u5 O+ `; F' ~
}
) x1 S; _% G5 a) g. o; \1 H }4 b# u& J' R; C, \$ q: T' i' M5 S
//类in_array函数9 A( L k F; \6 k3 X7 a. v
Array.prototype.in_array = function(e)
) z4 y4 [! I% I1 J( F {0 J5 x( Z! ?. z
for(i=0;i<this.length;i++)( G1 \; K/ W% |2 M4 d$ ^ s; q
{
; G0 }- r6 |& g if(this[i] == e)( l7 n) X* q u+ q4 M
return true;1 J! E, K5 o# A( ^) v ]2 Y0 \
}
) U; |+ E" R, z6 d9 h: a# T4 u return false;$ A/ |$ l' L8 h& o
}! B/ r+ V. C+ o! h D+ D
} 4 I( U' m4 L! B0 J# g! Z+ I# u: ]
mobile_device_detect("http://m.xxx.com");# r. }! r( t( X# h/ t
</SCRIPT> |
|