|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。; N E- J% @+ Y! g
6 W2 d$ U1 w1 J7 L; }0 D<SCRIPT LANGUAGE="JavaScript">( a' h. W9 r7 F1 ]; o3 i
function mobile_device_detect(url)5 j2 y4 c5 a E" k
{! t) Z1 ~6 P6 Z) ?. a( o
var thisOS=navigator.platform;) L% S( ?1 s& F! U& W* c3 A
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
0 b$ N3 ^1 e( O6 T, q: C for(var i=0;i<os.length;i++)
' j+ @1 S: E/ e S6 B* Z9 x6 g7 | {
# @" x3 A; i/ I5 F& ~ if(thisOS.match(os[i]))
# s0 h& S& u4 u) e. Z) V {
% m3 @3 G5 i8 f" M/ V) _( q window.location=url;, X' d- x1 m! q7 E: i: G
}
" D% `$ I4 @$ @& v 7 U3 X, @, m' x& ]* Z
}
( H3 ]8 z5 E1 ?& m0 u //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认5 Y% O8 J/ ]- G' Z
if(navigator.platform.indexOf('iPad') != -1), h2 X- {$ y. ]7 N
{; }/ V/ _3 w* M I( I
window.location=url;& G# {& \ ?% A6 h
}
2 F0 s* c! R. }; t. |& s! [/ e9 y) T //做这一部分是因为Android手机的内核也是Linux; p- O5 Z0 h+ v2 `& |, z) V
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
# J% ~: u+ [8 w) r var check = navigator.appVersion;7 Y2 `' j# W# v% w
if( check.match(/linux/i) )5 |1 ~) m9 x0 l! ~% H+ x3 m
{
0 ?: S, q8 i" y //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件* g; z; A+ p0 x
if(check.match(/mobile/i) || check.match(/X11/i))( h3 K" c, b f
{! o8 R/ f) o: r8 V8 F! Q! I- P/ L
window.location=url;0 O1 f; F/ \, D
}
4 s p n5 {) @2 Y* k2 ^ }" |; g0 A3 B$ B6 E. N
//类in_array函数1 c1 o" D Y+ v, c8 f8 B3 H
Array.prototype.in_array = function(e)
0 p, ~4 P9 m/ U {$ f( O% Z& c1 _3 t t1 g/ h
for(i=0;i<this.length;i++)* m0 \8 X: P5 I! p! Y
{
4 r* N; p A- h' x if(this[i] == e)2 Z$ A$ t% y; z$ T; G0 M+ f
return true;+ P2 M" Z7 a" ]; t, \' k
}3 o; T1 Z# o7 e5 s9 v- G; d5 C/ m& V
return false;. ]/ h, z5 g0 b0 u% U& \+ G
}4 l' u- S1 s- t5 B( r* T
}
# d# Q. Z. m3 e0 H mobile_device_detect("http://m.xxx.com");9 {9 v' x9 V2 q* u/ m
</SCRIPT> |
|