|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。! @) u) S2 `( F) [1 `
/ U% G0 T2 Y, n5 k1 o* S<SCRIPT LANGUAGE="JavaScript">
. F+ x, P8 b* Q. v function mobile_device_detect(url)
, _/ w4 T, n' X { ~/ ~9 W5 S; i
var thisOS=navigator.platform;
7 V" {# P. Z; a8 T, ? var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
$ c% F- w5 U6 \2 F, b# f: r for(var i=0;i<os.length;i++)
. ~9 H$ m- C8 v5 C1 o {
% f2 a2 S; R3 M w( [" F" V8 J if(thisOS.match(os[i]))6 ^+ |. y6 u% K4 v& Q
{ 3 g6 J5 G5 j- A P0 Y! o" _
window.location=url;% ^& `7 |7 y" l9 F
}; Z( p2 C7 o* M, p3 r
3 z9 K# _" A5 j' N }
0 y4 M+ B% c. {" B //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
9 ]5 M; F* z3 H1 y if(navigator.platform.indexOf('iPad') != -1)
5 I1 k5 v: Q/ D( `& d: v {
1 z0 L( A3 J; q( x- m i4 [ window.location=url;5 V; |$ `' D( Z) r1 P! H2 X% G9 d
}
" [) F) @& K+ S, W //做这一部分是因为Android手机的内核也是Linux
( m/ k2 K# h( |+ q4 _ //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
7 n8 m! T2 p! o" D& l) ^6 _% K# U var check = navigator.appVersion;5 k2 m w9 Z2 x! n; V6 F. y' V
if( check.match(/linux/i) )
& Z: k& O S1 [$ B. ^$ u9 p' Q {/ |3 E2 W& ]5 ]
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
* S) B( G$ i8 k( L2 k6 G if(check.match(/mobile/i) || check.match(/X11/i))5 R4 G' m$ P# P5 Z2 j
{
7 B; g! F# j) c1 P! d! | window.location=url;: M% ^" z: F6 V3 h! J
} 2 Z6 R9 R( |' C4 l$ x
}
1 A( H- G) C( w: l //类in_array函数1 E5 s. ~ \* S& i
Array.prototype.in_array = function(e) h! L) R7 t. m
{
. [$ t8 j& Y$ l( [; ]" l& { for(i=0;i<this.length;i++)
% j* j6 @6 V1 {5 f3 T' T {
' i& X4 O( U9 R( I if(this[i] == e)
6 \4 W8 s) Y8 W. a- L return true;3 Z$ B, O7 R/ f& N! y* z$ G2 s8 k
}
+ k8 U2 Z! Q3 h4 ` ^0 M6 Q. w return false;$ z9 T/ O# b% N1 Z
}
9 d j6 g1 I3 a2 e' ] }
3 Q( N. y0 G$ p5 Q7 u mobile_device_detect("http://m.xxx.com");5 E2 K) U4 |# N: b" Y! `1 }: i
</SCRIPT> |
|