|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
2 x" y+ E$ U6 d
\2 e$ t# _+ P<SCRIPT LANGUAGE="JavaScript">
+ @* t7 Q/ e. k6 L0 r/ G function mobile_device_detect(url)- j. I* u0 u$ e" r- e& f4 ^ i% S
{
7 Z3 b& A/ Y1 `& a var thisOS=navigator.platform;
/ I# n+ k9 u8 o8 p var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
& M' r# r7 M O: `- \7 X& g for(var i=0;i<os.length;i++)
3 s8 H: j3 }- C% L! I& S4 l- N {
( o; x9 I( G7 ]. H% J if(thisOS.match(os[i]))
2 Q3 H+ |1 t4 X: A( s5 H) [1 ] {
9 H+ G- q/ r# s8 j6 o7 r" R9 t window.location=url;
x5 W" g5 Q% p }
3 _& {' B9 C/ M; I* p+ \8 ^: ?; N# C
# ]2 K9 c1 W! n/ K/ f- k }
+ H% L: W2 h$ \. e! U //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认) _1 o8 p7 \& l7 q# l# ^
if(navigator.platform.indexOf('iPad') != -1)
/ M2 ]/ L- |7 B, u' N! Z4 w {8 X+ ?+ H! P: h
window.location=url;
' n, U/ I% H" @6 Y9 ^- ?/ V }
) Z6 X7 ~- Z% M0 ]! I% _ //做这一部分是因为Android手机的内核也是Linux
]8 u! I, d/ {- R1 ] //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
+ M% k+ c0 x* _5 x& S6 n var check = navigator.appVersion;) V! A3 I- V2 R
if( check.match(/linux/i) )
2 R0 p: M% W( Z5 Z# t ~5 Z( n {
# T9 W2 n5 O( k0 B! R' d //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
& d" L/ G$ ^) ^* j if(check.match(/mobile/i) || check.match(/X11/i))% j, K0 W$ ^$ w( O% h3 d/ L
{
0 F( z$ k2 u' Q9 X window.location=url;
8 D2 z/ x8 q. c/ @0 h$ e } 7 L# {7 I4 @6 D# }# l4 u5 ]
}
4 F) S8 E9 ]' r* r7 n; S //类in_array函数
2 x$ l1 j0 |4 g& r Array.prototype.in_array = function(e)
5 l+ g" T$ Q: T3 ]1 \# w( \, j {
) Z" l4 f* P* m0 D7 u+ W, E" m. M for(i=0;i<this.length;i++)
" V" L, T0 ^3 G& @ {
1 L5 G/ C( e: K& ~& a if(this[i] == e)% v, N8 } }' N5 E* g6 m' f" R
return true;
7 S# P K6 _3 S" Z0 q }
0 _: V$ w, h' r V$ A; ~0 ~ return false;
& |, v1 R, k O2 [& {) w }/ G; `1 e( u& x" ^: i1 C
} 7 }8 u) f' B* T" v# L/ M
mobile_device_detect("http://m.xxx.com");
7 D$ W8 x8 l! }6 W/ \ </SCRIPT> |
|