|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。# r+ a" A4 Q3 t, }* F/ h' B% r
0 \" D7 s. ?/ E( [2 Q' e<SCRIPT LANGUAGE="JavaScript">; p5 T8 \- F& P( k8 J5 x$ Q, K
function mobile_device_detect(url)
+ d1 {, S1 |+ |0 f {
# g* c2 L6 ~" ]0 Z- A var thisOS=navigator.platform;3 z, D. b* t- q- ^2 D" h; T. r( Z% c
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");+ @8 j/ t" \$ Y1 x$ S d- `
for(var i=0;i<os.length;i++)
4 i& c- ?+ _: L8 n% Q: g {
4 @% h- P1 i, j" X+ b3 ?6 G' _) m if(thisOS.match(os[i]))$ u) r( W# ~9 P# W5 R
{ 2 `# p/ e6 u& J) ^7 p0 [
window.location=url;
: G% ?" m' O$ i6 u5 p- t: V }4 G2 C3 V; @2 x( M5 ?, \& Z
' X: F+ N* b z: o2 o% c! E }) f4 R: ]1 u2 i) b/ R
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认- v8 i& m7 O& K) T
if(navigator.platform.indexOf('iPad') != -1)* U: I9 A( e5 d. @2 z$ `
{7 Q4 A1 g1 w! ~% E7 N. a( M) ^
window.location=url;
' k y7 U7 V4 x) Q }
1 @: a. f. x+ N; P/ \& _ //做这一部分是因为Android手机的内核也是Linux
* L" J& Z( e: E; |7 D3 C1 D. v X3 f //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断% P8 @! w" u T; ]( |
var check = navigator.appVersion;
2 ~4 X9 ]" \! s if( check.match(/linux/i) )
3 d( m! Z- \- z$ u5 S {2 Q0 W" @7 D& _( w s2 W
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
1 d% P* `1 w* f6 J if(check.match(/mobile/i) || check.match(/X11/i))
O7 _" J4 m8 |/ B {5 E G9 ^: \/ w4 v) R
window.location=url;$ ]8 i0 y6 F% b
} " S& K1 R* w" v
}
l! G' b& P/ }/ I, o //类in_array函数
' [; H$ ]: t w! V* O0 s Array.prototype.in_array = function(e)! u1 P# ~0 D4 m' o, P0 p3 X
{7 b* X+ M3 k/ B, D( o: G; s/ g
for(i=0;i<this.length;i++)
$ T0 ^" e" K- \/ k5 D/ m' a {4 r) _ c, t5 h2 w' H
if(this[i] == e)
' ~0 V& x) h4 U1 O f return true;0 Q) j4 D+ [! Z c
}
0 _' L; L+ I# f7 P return false;' `0 ~& P f0 z& Q; N: C
}" w& B ]6 h- u! W1 O$ l: K5 J* n
} ! t9 \8 ^! q$ ~
mobile_device_detect("http://m.xxx.com");
1 p5 z3 s/ g1 {3 e4 t' v: E </SCRIPT> |
|