|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
6 G2 ~2 }! ^$ C# U3 l( Y9 P$ }1 G
<SCRIPT LANGUAGE="JavaScript">
2 G! b0 Z" C9 }) n0 A$ i) p; z. ] @# ? function mobile_device_detect(url)* j+ v% |, F4 h$ o7 Q8 k5 ~
{
) H+ c+ g* E5 f. B6 R" U var thisOS=navigator.platform;) ?* D' s9 `" ]2 z1 n: I
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
l- v( `/ B( d6 A% K' S/ m for(var i=0;i<os.length;i++)+ x6 T3 g4 R. E1 d
{
1 n% R4 O: f5 G- z H: o: N if(thisOS.match(os[i]))
3 I; ]: f/ C, ^( M* ? e { * u2 K8 s% H. l6 ]. f8 f
window.location=url;- k& N. i, R( d N; W; J
}/ D) V; j s. Q2 u/ \" ]2 M
8 S& I, x! K9 r) [! T }
1 Z3 S" }0 [1 o //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认2 B( D0 {6 E& U8 F; }
if(navigator.platform.indexOf('iPad') != -1)* X$ y$ m7 M, X \- h$ ~
{
. f! x; U* L5 E window.location=url; }4 m( V7 h5 b5 W7 B% q0 W; Q9 l
}
( \8 L3 c7 y" E' e/ [ //做这一部分是因为Android手机的内核也是Linux
) u3 S; S' x* A" [ //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
8 p1 I! a1 g0 W. y8 y var check = navigator.appVersion;
2 t% W8 r4 @9 u8 I$ Y5 K if( check.match(/linux/i) )
( W5 V0 w* r* i) U {
# h5 i+ Z; M8 u5 { //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
( `2 f7 L: J1 |/ d _ if(check.match(/mobile/i) || check.match(/X11/i))
9 Z* M0 W' [5 \! i, C$ U {5 U+ b- B, h/ ?$ z
window.location=url;
; g. i8 Y ]5 o% K- r) h6 ?- K$ { } + |8 o- R! r0 m n5 u
}9 _" K& P( ?" J" A2 O/ l4 e7 F. _
//类in_array函数
5 R! _' V/ E! k! k Array.prototype.in_array = function(e)
- m8 f2 n$ {$ U o5 M3 ?" Q! h( `! | {
3 |( E7 T6 l: {# ]3 K2 E# Y for(i=0;i<this.length;i++)
2 t0 Y; H0 x8 G9 a3 D' h0 n$ Y {
- R! `7 i! Z/ w5 Z if(this[i] == e)# e* L. j# ~; _$ E6 ?0 O
return true;4 a# B( ?/ z3 O) ?# G8 A) T; h
}
8 D( E0 S. ]1 m6 T' T return false;
& u- G6 ^* p* B- S. y' b }
9 O3 C/ ~: s% P* v$ G }
5 G5 l# T1 D% c mobile_device_detect("http://m.xxx.com");* X) V( C8 b7 [# i: w
</SCRIPT> |
|