|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
. J4 f2 x+ |- }) O0 K( e [' P5 g k1 q! P$ o* C i
<SCRIPT LANGUAGE="JavaScript">/ C, a5 f. _. @6 _& F
function mobile_device_detect(url)
" D7 t& E5 j ?8 W. ^2 ] {! _: @' z. ^% F! H- Z3 o
var thisOS=navigator.platform;
?6 Z. x3 }, N/ |, ~ var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");4 a' i! l- c$ [4 @, E
for(var i=0;i<os.length;i++)- _' v$ v4 W+ i( V/ x
{& W: K) Z3 Q9 C8 A M* M: q
if(thisOS.match(os[i]))" A! p. U, p9 h
{ w; V1 B+ T1 L
window.location=url;
# T/ y* J$ O1 L. \+ M, b }
3 Z5 ]' v: q) S8 ~ . E. i! T/ C4 J8 m- S2 G! G
}
7 [ \" {: D8 [ //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
( \# S* P% z9 _4 N8 } if(navigator.platform.indexOf('iPad') != -1)2 T9 n4 s. Z7 h! G( `# j
{; x8 p+ F) _" A
window.location=url;7 F$ R; F' |& Z% ^2 m0 f
}
6 P# n/ T4 m" b //做这一部分是因为Android手机的内核也是Linux
2 K4 l9 W( n0 P' a$ N3 v, _ //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
# l5 ~# T6 H: P var check = navigator.appVersion;: a6 H) [; M1 V j
if( check.match(/linux/i) )
$ ^1 M* u, h0 {% l1 o {& w! ~" h5 d& ~' K9 _1 V1 Q! m, P, x
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
~" ~5 v7 e$ `3 B( ^% Q if(check.match(/mobile/i) || check.match(/X11/i))
5 S6 n9 ~1 l: Y8 Q! ] {
# `: H, N9 K! F: d ] window.location=url;
& ]1 X- m' p' q } ) u, A3 ~8 e! n) H2 q s
}
4 W5 x+ d j" f g //类in_array函数
1 Z, l/ x1 l# W* I, }/ O/ Z) X Array.prototype.in_array = function(e)# H+ a: \1 i" t) Y
{1 @8 x* i1 m& [# {2 c
for(i=0;i<this.length;i++)
* k& Y7 N9 u0 t {
$ I$ P3 i* u2 d( Y( W if(this[i] == e)
6 F$ B) ^' e8 F) C return true;! c- J, ~- B0 d$ z) w
}; K1 B' o6 D2 ?) h" J) \7 E
return false;2 d/ D" h2 q$ D$ J
}
' }5 [3 ?) H; ~* l, R: a+ M }
1 ~1 ^$ Z' \( U, D# } mobile_device_detect("http://m.xxx.com");. q; {) c7 C/ n- w7 e
</SCRIPT> |
|