|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。6 H, u! b' ~- f- Y& T
3 h3 f2 N0 h# q* V# D& _<SCRIPT LANGUAGE="JavaScript">
2 m9 B. N/ }( N function mobile_device_detect(url)5 y0 H( u7 `0 ~/ u) [
{& S, c0 r4 s4 X/ ^3 K: i8 S
var thisOS=navigator.platform;
! `% t' b9 \+ e' 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");
" g: T7 E7 s/ B9 e6 `! l for(var i=0;i<os.length;i++)
/ c2 k/ n/ i# U' g# }2 ^ {- U4 d$ k* P; \" u* G2 j" D/ k
if(thisOS.match(os[i]))' J- L& p: k& t* [
{ ( F. Q; [* Z/ `0 U- M
window.location=url;
8 ^2 |1 d0 t; g8 s% ] }. | m6 r' k/ R( A6 p; z! G. v
* x9 l, X- f3 d8 h( V+ U& C& a
}
; P6 I+ N, e. s1 V2 Y3 f0 k& Q( @ //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
6 E$ W3 O5 g7 Z! o3 F if(navigator.platform.indexOf('iPad') != -1)
! s. D. W! K! A7 O C2 i {' j; N- O% c7 M5 q. _( j7 m: b! r% _
window.location=url;; W0 ?, Y8 O9 @( x
}
% n# ` x; O% @2 W7 L //做这一部分是因为Android手机的内核也是Linux
4 ~/ j, s1 p0 X+ _! a //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
: s0 G8 U" _$ G7 R4 d& ?" l var check = navigator.appVersion;6 ]+ R; F! C, c3 b5 y
if( check.match(/linux/i) )& o. @9 C; g3 ?5 [* ~
{
9 h, u4 |, Z6 r2 {. ] //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件0 e) @3 g p, m, G
if(check.match(/mobile/i) || check.match(/X11/i))+ U) ^( t; s! g
{
& V- [8 j- {4 s( U5 F6 b window.location=url;
' Z! |( O `8 g. N5 U }
9 Z1 V" R$ R0 p0 ~. { }5 s! S, h( D+ D: R* H/ Z
//类in_array函数
+ V, P7 [6 y+ v! t Array.prototype.in_array = function(e)
* o: Z$ U! y' w9 a/ y8 F* y {0 Q, E; l/ A. I& J
for(i=0;i<this.length;i++)
1 k8 r+ h% t0 Z" E {
8 g. i0 ^5 o; w: l" D if(this[i] == e)* `( A1 S/ y9 N; x! i
return true;" h, N ~" N% \ n. e9 i5 t3 e
}" h) J( c8 F3 Z- i' H" E
return false;
7 p5 c! R' {' `( p! j }
. I6 v9 u: D! P! A& e" D9 p; ? }
# w' \6 z4 r4 l mobile_device_detect("http://m.xxx.com");! _: l7 S+ ^5 J9 v
</SCRIPT> |
|