|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。! p$ J9 e1 R, R. l0 [+ w3 K4 g
( m1 P0 ]: M% V/ a8 G
<SCRIPT LANGUAGE="JavaScript">2 }% X3 X' y9 v$ S. F9 X. h5 c" L
function mobile_device_detect(url)
. x& [; Z7 K) N- c/ Q* P, q h- k/ f { K: m! K' v1 G, [
var thisOS=navigator.platform;
: O" y6 q9 A# [6 F. @ var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
$ Y/ G" W* m# u6 W- y for(var i=0;i<os.length;i++)
+ l3 t0 _8 f$ |* i# \# | {
1 u& o. A, _$ _ if(thisOS.match(os[i]))
8 R+ v2 |$ s: c2 T {
* c- o8 @1 Z7 m% s/ U window.location=url;! T, c. p/ d/ f5 {2 H2 J
}
1 @6 \9 u& ~3 E P4 Y6 f$ V
8 c4 Z" z( x" ^, c a }2 e" E5 p/ n4 J4 C
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
* \* D1 R5 W. V0 L) q7 Q8 s5 g if(navigator.platform.indexOf('iPad') != -1)
8 O: }4 |2 w; C$ p+ D; f; g {9 z4 Y5 L0 l' B, O) y; U
window.location=url;4 W: [: E" V6 D
}
, k# @+ o/ X, ?: z3 q a //做这一部分是因为Android手机的内核也是Linux
* `1 j$ M: T! f2 ]$ }# D //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
* `/ f; {1 ?6 i0 |! m( m var check = navigator.appVersion;
4 A4 a- Y9 r' D( u- Y+ h# \2 | if( check.match(/linux/i) )
- V* L* w! V- o# a+ Z {1 _0 G( T; g5 j
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
9 [' Y; G8 {+ H( v# J B if(check.match(/mobile/i) || check.match(/X11/i))
$ Y0 X2 M) ]& x% _ {
3 K, y, i* G O0 u0 {* G% `. ^1 y window.location=url;% b; ]1 R& C" @8 {9 \+ f
}
3 T3 h: N; }. y- L) w }
/ G7 A, ~$ S% J! h3 k //类in_array函数
( T) x, i, V; K4 i1 [ Array.prototype.in_array = function(e)
; S9 T5 a& g) y2 P' @! n. c7 H7 c" B {3 p$ q& \5 z& f
for(i=0;i<this.length;i++)
% L, y5 C H$ l {; Q7 S, k' K, |% @# @3 G8 M9 V
if(this[i] == e)# y5 A% W- O% A7 n
return true;* a1 x( E0 G! y7 d( J' X9 q
}+ S$ M$ J5 o* X- r. y* ]! ]
return false;
U [- A1 A' T$ M$ U' Y1 b }
{2 W/ v( _& B0 w } . c7 L" g, U2 Y1 }6 ]$ s
mobile_device_detect("http://m.xxx.com");
! X; H- C* I$ ~4 @8 E </SCRIPT> |
|