|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。( |, c5 F$ [6 M( m! `
$ `$ K7 g9 b1 i<SCRIPT LANGUAGE="JavaScript">0 Y& q! v+ n8 {9 m' {
function mobile_device_detect(url)
) }1 l; c- e- b4 O { z! u' Z' t" P+ I3 c
var thisOS=navigator.platform;
1 q5 M1 D7 |+ @6 U7 t. 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");9 Z: \' k) ?' H O: g6 c
for(var i=0;i<os.length;i++)- c$ |* W- [9 Z7 V: k( X; c* F
{+ }3 j# U) G" t) P, m( i
if(thisOS.match(os[i]))2 _5 X( {% G* g+ T8 f' r+ Y( h S" h
{ - z2 j8 _, Q' A r; s: ^, P8 s
window.location=url;
0 {3 V' d( a: T }& D8 i$ J8 l; }* M
7 |- }+ x; S$ _- F* p, C$ m }3 l' p6 z# }# G( l( z6 C' r/ D
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
* x* g0 ? K1 }0 c! o. ?+ H9 r if(navigator.platform.indexOf('iPad') != -1)* L. w8 O7 M! k: b) E& ~
{+ G- U2 I% i2 t
window.location=url; x/ y$ z8 Q5 S; x: W) t& m; m
}) \% P+ S0 R& D
//做这一部分是因为Android手机的内核也是Linux3 K, j" [- \) I# `# o7 I2 m* z3 A
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断" j" _2 a% D ~* Z' q, h2 M
var check = navigator.appVersion;6 n! n7 _, p1 j& p% W) i
if( check.match(/linux/i) )
+ ~$ y* R6 ?$ F! b5 ? {" I, }% O1 Y+ s: @2 j2 |
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件2 w( _' ?, Q W$ d& B$ E4 y
if(check.match(/mobile/i) || check.match(/X11/i))
2 a+ K) @3 M" M9 m( V$ t, c# ~6 A {
4 ^* F- Y: y3 M4 h7 [ window.location=url;* D2 G) y4 Z2 Y+ e. \6 Y" H
} 6 V- c$ E1 n J8 z5 D. n
}
% E0 R& P0 [3 s" g1 H9 j //类in_array函数
1 X2 S( C' p% l Array.prototype.in_array = function(e)
6 ~1 E. z! H+ M, W! }* v' | {5 {9 G6 m1 T: J! k9 L
for(i=0;i<this.length;i++)! T, x9 [( @5 Y& F) x: T' o6 t
{
2 x' e9 z8 o% D* a) o if(this[i] == e): k. z1 o' W' G- Y/ d
return true;: U* v% |! y; w! t7 D; P0 F
}
' T1 s& N1 i+ {3 O3 }' A* S8 o return false;
, _9 l7 n8 o; l6 b" _ }
0 s- T9 u8 A1 A( d5 w! X. |: F } : d% D9 C+ B. }1 V+ E, I: `
mobile_device_detect("http://m.xxx.com");7 f" Y) m: S: | I
</SCRIPT> |
|