|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
4 `- d; i1 X" k& L$ C6 ]
, e* f) g/ I) ] g0 Y& V<SCRIPT LANGUAGE="JavaScript">" v' @+ `: p3 y9 }- a/ ?
function mobile_device_detect(url)9 m9 W- o7 q# G2 ^
{0 h5 e: L! w% z9 l
var thisOS=navigator.platform;
3 p0 w) B$ E! V9 C' o var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");: D. J4 y% ?( _! E6 H
for(var i=0;i<os.length;i++)& S8 `. X. w# d$ s
{
* P" l2 g3 H+ b if(thisOS.match(os[i]))( p% p# k! Q- C
{ # G5 @6 }) H- {! `8 I
window.location=url;
( `4 I) W* K6 X% _( Y }8 b$ Z6 H* O9 B* X( j* H
) s1 Y6 T1 ?' M8 z, l+ ^
}) G; r8 z* M- H! A
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
7 |- O9 F. R; v0 ] if(navigator.platform.indexOf('iPad') != -1)
. U5 G! D6 D+ P p: f* `# Z {
: n6 ?! m* I8 P" @4 V5 ~6 C window.location=url;
! D( |/ t& r* N( w$ | }
( D$ m8 z% W- s( w% Z //做这一部分是因为Android手机的内核也是Linux
1 ^5 k' ^1 d/ o& d! D //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断1 K3 ~' ]6 i. D, Q0 z1 l' ^) k
var check = navigator.appVersion;6 p$ h+ q P) i+ ~5 j5 F
if( check.match(/linux/i) )
$ k0 _# E- @: e {2 S5 _% l# x0 h" f( h
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件4 i& q% n1 A% @" a3 t7 R- i0 f
if(check.match(/mobile/i) || check.match(/X11/i)), e7 a4 M8 n! s) l! l; r
{
( z! o. S/ ?- ?1 Z7 Q# u' m. u window.location=url;% _. z0 [+ n- O* ]
}
# a% l8 _, k( v4 n& v( _ }+ n, A5 Y& b* p5 \7 N5 t
//类in_array函数! F( S" {* b; C0 U
Array.prototype.in_array = function(e)' o2 y3 @3 }& e9 {
{
3 `7 R- k! |% X7 ^% _ for(i=0;i<this.length;i++)8 E0 D0 \$ ^' ~5 d2 z, Q, F
{* e5 u( [3 R& N! z6 o3 z7 T
if(this[i] == e)
H2 |! v0 F6 Q( @. v2 w# d8 }; e, ] return true;
; D; @3 \& w) |6 q4 t# A }! |8 h* o# H8 P6 x# [
return false;7 B" l- d; v; Z3 S+ p4 l
}
- [, | x" d& Z } " c/ O2 h" F* N3 t
mobile_device_detect("http://m.xxx.com");
" ^4 U- X- t+ G </SCRIPT> |
|