|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
, o U5 T9 H6 O) c/ |% C2 G9 v# a# o9 G7 g
<SCRIPT LANGUAGE="JavaScript">
$ d+ k/ a( m, e" F# t4 {5 u function mobile_device_detect(url)4 }2 q- _+ U" l r8 y' S
{
# o% B. ~ \& I4 _ s" V var thisOS=navigator.platform;; j' v6 m3 U! Z& ~ n4 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");2 C* }2 W$ [2 w& j
for(var i=0;i<os.length;i++)+ P5 G; J: k" V8 e f2 d+ W
{, [1 ]: c6 r4 p
if(thisOS.match(os[i]))
9 i! j% G9 _) w, x G { 6 C: b& f9 I: S" N( w, O
window.location=url;
' u r# T8 y6 \! [8 {! b8 O1 W }
6 {. @: \8 g' e! {
+ J* ?+ J4 l, B, j- D }
- u( g# z5 m+ a. A //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认) x8 Z9 H6 s0 t) K3 w: M4 c. ?% T
if(navigator.platform.indexOf('iPad') != -1)7 g7 f# b7 ?0 a
{
# V. O) u9 Q# d5 Q( B0 L window.location=url;; D! D, f' j* F& ^# y
}
' l: t# H, E G% F //做这一部分是因为Android手机的内核也是Linux% C: J7 D. i8 P$ ?
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断3 m |8 M; K9 [9 M
var check = navigator.appVersion;2 i% t) N+ ?; \5 O( W
if( check.match(/linux/i) )/ h. u/ W, E# v- y$ V$ X* g
{ q5 |! K' f3 G" i% ?" ~) G
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
$ t) ]+ u" T/ z. S8 E' ^' J if(check.match(/mobile/i) || check.match(/X11/i)), V! }/ K% l; Y
{
6 w$ A1 {9 |+ R+ j% @ window.location=url;- h) j. u% W2 F8 V0 @8 O
}
# u! h9 i( I4 F( E }; l3 _0 x) H/ P8 c# T
//类in_array函数
9 P* f6 T+ G6 Y4 M$ i& M# L Array.prototype.in_array = function(e)- P) G8 j$ b# P: }
{: Z0 V. v1 r8 _0 a# T, Q% D
for(i=0;i<this.length;i++)( b: m& U: o6 U0 T
{
! Z x; |/ e: E if(this[i] == e)
+ s8 p Y; J, s0 f return true;
: m$ K) z* i. v }# o1 a" n* W" E% h8 B! n
return false;
% a/ }0 P& D# Z/ t }7 l! s9 ^8 ]2 o5 D
} $ k! Y1 N- ~( i. W" J8 u
mobile_device_detect("http://m.xxx.com");3 w! s8 H* l+ }
</SCRIPT> |
|