|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
! i" s- k7 _ r. n$ A% H$ R1 r- T/ F- x h% Z
<SCRIPT LANGUAGE="JavaScript">
+ n1 i/ ~2 w4 z, D/ C. P9 t function mobile_device_detect(url)& V2 T9 b, F" r4 N# `" s
{# e- H$ N$ l2 B) b+ N# S, f
var thisOS=navigator.platform;9 I5 |/ Q" c; u& y' `( E) v
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
1 u3 m2 H2 `' P, k( P1 V for(var i=0;i<os.length;i++)
8 R' v; L& l8 l- v {
6 j. t% z6 `% I2 R$ S' l( w, _ if(thisOS.match(os[i]))0 P: C e m6 x' S% ^
{
* w# M9 u1 _8 p9 i window.location=url;
( A4 G5 k2 M/ Y9 t }
+ _1 C! e# `" B, o 6 q) u7 H1 d: [" ]& v
}' }9 D0 ^& s5 a- @. u4 p
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认 x1 ^8 h! g2 h5 Z# h! x9 \
if(navigator.platform.indexOf('iPad') != -1)
2 {. |+ d9 q! K/ e2 |) z' M {( A1 @ p2 l: ]
window.location=url;
+ K# Q$ K/ `, w1 t9 q( o6 m- E( Y }+ g; b6 M' d5 Y" O4 c8 ^% F/ w# x, W
//做这一部分是因为Android手机的内核也是Linux
! _9 p6 W4 L B$ x1 d //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
' i6 a- \) c* W4 I* w8 c) T var check = navigator.appVersion;) O* h; F; @$ e3 \5 Z+ T3 D
if( check.match(/linux/i) )
x1 q6 n9 S& b0 y {
! y V3 A o: r z //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件$ ~" Y" F4 F8 @% p1 U
if(check.match(/mobile/i) || check.match(/X11/i))# d+ z! A% P' F+ V: \
{8 n7 l, c2 M9 D7 E* N$ t5 v
window.location=url;- ^ Z" |( U5 {; M/ \
} ) I! w8 f7 r: e9 i- T
}
& J: X7 f9 F; O //类in_array函数
. H3 S* H1 L% ` Array.prototype.in_array = function(e)8 G; c8 s L9 q2 k
{& x; D6 N5 O: P+ z1 m
for(i=0;i<this.length;i++)
: |+ s# ~: d$ h' z! e @ {
' A2 b. ^) x! ^0 B1 w4 c4 o. k if(this[i] == e)! K" q5 ^) L/ X9 z d2 |
return true;. {+ R4 o* Q$ S. c# E( O$ u; W$ e
}/ \, \6 z$ v8 k9 n
return false;
1 H: U4 F# ?& ^; T6 d U: c }& b* k. s: i4 N$ H1 i5 b4 L
}
( ?1 y( f/ k4 I$ U mobile_device_detect("http://m.xxx.com");
( m) k$ k& n/ d6 q$ x </SCRIPT> |
|