|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
- R* b- l7 |' ]% F# X0 M8 o7 W) R) s, J& @! f1 _" s
<SCRIPT LANGUAGE="JavaScript">
" Y$ L, U# T8 O! Q7 e* M, o! j& G( f function mobile_device_detect(url). \. e6 z$ V8 R& j
{
$ P& ]/ [" c0 Z" J var thisOS=navigator.platform;
7 g5 y& w6 n& V$ F5 } 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 F7 S/ y0 k$ V3 `/ f, s( n3 _# B. B for(var i=0;i<os.length;i++)& T% O3 }+ c! {# y/ {' ?) J6 x
{
1 l1 K% C9 ?7 }+ f if(thisOS.match(os[i])); S j" f( e+ u6 y% k0 R/ z1 \
{
7 @" z1 _8 F3 q: W% s' b- b window.location=url;! x; k% H, y* ~! }
}
4 D! }# L" o8 d/ A* ], \; A
. X& L7 a( {% p3 G( X# k }
* |* _! C* Q8 A6 {$ Q/ x //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认 q# x. {+ ?# h% c2 }8 c
if(navigator.platform.indexOf('iPad') != -1)7 f# c c# U# z, i2 F% A5 C
{
- K+ b+ O! H! O" Y" L4 r0 p window.location=url;- T/ m( {/ {$ X0 e5 Z" ^6 R
}. T5 x# N! b- e5 q# J k
//做这一部分是因为Android手机的内核也是Linux3 F9 s4 c! n" S$ f
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
/ s' J/ p6 `% n0 ^ var check = navigator.appVersion;
4 _+ m' e! v; M( G; T6 ?, ` R if( check.match(/linux/i) )% E* k4 Q; M' Z8 g C
{& o& j+ K6 A. Y/ B+ t3 W
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件! G: y# M' W/ Z1 ~
if(check.match(/mobile/i) || check.match(/X11/i))9 [2 r, ?, e0 t4 A* t/ r' a
{5 U% v+ j- G& ?, n
window.location=url;
1 \7 |) f; F+ {* M: | } 1 O! D, i" q' P0 N
}) U3 V1 W8 O9 @ y, b
//类in_array函数! E6 z/ M; `" Q
Array.prototype.in_array = function(e)& h1 ^; d; e6 f2 `% e f9 \
{' U0 G+ c) x# \ D: X
for(i=0;i<this.length;i++)
( s- H( [: L# x: i$ D% {3 i6 L4 b) Q" C5 i {
9 v' s4 s1 h) V ]0 j if(this[i] == e)
4 F4 I7 _/ g3 K1 |" ]8 ~ return true;
4 G% o9 {/ }& D% @0 ~ m* p, V |: x }! |8 L, S/ d& a/ L! F' ^% R2 B! f- V
return false;2 V/ s5 q- Z: g' }: i8 U* O, s
}
; D; W9 X! V j! _* ` } X) V" s( B2 X9 f: T
mobile_device_detect("http://m.xxx.com");- Z% ^/ ^ s7 P, T' \5 E! Z
</SCRIPT> |
|