|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。& i5 |' b$ k5 N( Z; G
" M9 y7 W/ E+ W& h<SCRIPT LANGUAGE="JavaScript">9 b8 U/ H7 I9 U X3 d4 J
function mobile_device_detect(url)8 S( B; ~5 \4 O
{
! ^6 y/ R3 ?2 ]) v" U# X4 D. C9 ~ var thisOS=navigator.platform;: {& C9 n# k, ^* u( a% o
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
/ A. e# a2 S1 j1 C for(var i=0;i<os.length;i++)
+ S5 {: \- v% ^- r {
f3 k! R8 u% w* e. P if(thisOS.match(os[i]))
# C& ]% q; Y3 w! A+ a; X' n7 x( Y {
" M0 ?9 P# p3 I% n/ r window.location=url;
* {! ^3 P$ t9 E }3 _! Y1 t- V% M4 {. i/ V
% x) O% j, i2 R" t+ W: U
}
" `0 l0 a" F4 z, j) c2 d6 t! [ //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
* R& W% @4 U5 i% n2 O2 j if(navigator.platform.indexOf('iPad') != -1)
: `* Q( d/ m3 N2 S! ~2 @4 }* L {
7 ~' b! X) C% \/ e& p# R0 t4 q window.location=url;
: L+ R4 v% g+ M- E }. D2 ~% n; D7 K2 [+ x/ T
//做这一部分是因为Android手机的内核也是Linux
8 f$ s; I* r w( P; X4 q6 k //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断- M) K0 h1 q# y9 F# H
var check = navigator.appVersion;# }5 R* ?1 h: ]/ A- `
if( check.match(/linux/i) )/ @8 M5 d f: }) Z
{5 a7 ]* F x5 L) x# c3 u- A, d
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
- ?! T2 y9 ^7 | if(check.match(/mobile/i) || check.match(/X11/i))
1 N& I5 `# l+ \" i) ]# ? d {
# N* |4 i& _1 y% ?. ^& \) _* L window.location=url;
* n ]! \- t: l0 v8 L# K! S, B5 L6 M } ( }! P' g. F2 F/ t+ A
}# g u. R Z5 R( @/ m
//类in_array函数. c7 s7 ^+ y4 b6 u# \ i# S/ |
Array.prototype.in_array = function(e)
# u8 G# E* x2 ` {1 H5 F% p& g6 I& L
for(i=0;i<this.length;i++)
# z! i' W+ Q+ C; J* f {
. o' p! z# ?' h3 W! z4 a' G- x if(this[i] == e)
: [* D4 E j- j% G4 D) h return true;( O' J4 b! W0 z7 x
}
$ c, ?. d/ O2 R8 A3 j/ P/ T7 S return false;! @/ c9 Y0 ^" d/ u' e
}
* q# O' {- z% U9 [3 } }
3 D; Z6 ^) d. w& N; ] mobile_device_detect("http://m.xxx.com");# v% i1 L- c6 [% H% w. w K
</SCRIPT> |
|