|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。6 K' P6 w5 s3 o# Z$ @; [& g! t& s& B( B
7 j1 J q6 j9 P0 z# N! o<SCRIPT LANGUAGE="JavaScript">2 Y. {; S$ ?$ m) Q
function mobile_device_detect(url)
8 {: M n- h! v& o9 }# J& |, X {" r; y, _, w% j& ~$ R: I
var thisOS=navigator.platform;7 A. c/ L& i- J. |
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");; l" @: @9 x( _
for(var i=0;i<os.length;i++)
, H9 V U) c6 k {
$ S2 x6 k$ e, G: J8 ^: O6 H if(thisOS.match(os[i]))
0 Q4 h( v6 b+ t: q' Y5 [9 M { 7 J) J) z5 h& Y3 h& n3 z
window.location=url;; B5 r" Z# I$ i- L0 q
}- Q$ I) o2 \; T3 Z9 @' Y4 g+ t# M
; V4 | @: D' Y }
F1 ^: _, |: r4 \8 ?/ Z' R4 H# X //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
( _8 Q0 m! Y( y) T! j if(navigator.platform.indexOf('iPad') != -1)
* o- w: M. a9 o, G. Y' ]% R- J {4 `- E2 \* X) N) D c+ J" E$ h
window.location=url;/ a* {' U3 ?1 r2 N
}; b) L; B4 e/ z! I8 c& R
//做这一部分是因为Android手机的内核也是Linux/ P7 i0 r% k% F
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
9 n V& }" M( c var check = navigator.appVersion;% O4 x; `% C4 u% K/ ?
if( check.match(/linux/i) ). Q0 E6 k$ \( y
{: g' V7 r) F) \
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
, e. c q: L- a' M% W if(check.match(/mobile/i) || check.match(/X11/i))
* v) X7 X' ^0 k! Z {' Z4 k- o3 o8 }
window.location=url;
1 c. n8 y( H, b+ G: K+ Z# K* W% ? } . L" ]: M% P \; w0 K
}1 \$ L" _0 D9 F* C* C2 u1 x5 Q' n( `
//类in_array函数
1 n) \! l n7 T# z( X Array.prototype.in_array = function(e)
( ]) `- i( O% k8 B% u k0 X9 u; O {) i+ o' t+ U5 V
for(i=0;i<this.length;i++)
2 _" u# m* L& z0 e6 `( d# [7 s. r {! v* `& Q' J" F, [1 i# \/ B8 ^8 \
if(this[i] == e)! u1 J- @- O8 Z7 x# j# D
return true;
~! ?( `" t7 n8 n! Q }! M4 v4 `( B" n" B8 ]5 N5 g
return false;
$ c, F8 g( B0 g! {. |, @ }
; ~2 Y1 _4 D. O! | } 1 ~$ L( Y+ y$ _2 I. d h0 Y
mobile_device_detect("http://m.xxx.com");
5 {/ S" {0 ~' t </SCRIPT> |
|