|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
8 R% p2 _) n0 v/ @9 \4 b2 K' i- C: u$ n( O0 N" C5 M3 m& g
<SCRIPT LANGUAGE="JavaScript">* k1 b' t/ L8 l0 k- ^9 B. m
function mobile_device_detect(url)3 P2 X$ x7 e7 L. I7 @- f
{/ V' e0 z5 f6 {+ n0 J+ T* E* M
var thisOS=navigator.platform;
2 b% q3 _) e! B" a1 g0 D var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
|' F1 {' X1 V0 O for(var i=0;i<os.length;i++)
" d& Z- R0 ]% B% c4 ]! i/ c8 ^ {
' o' H8 k2 n9 B; M# j; Z$ N5 m if(thisOS.match(os[i])), L% i$ H% j* W. W' h5 y
{ 1 x% u& t8 {1 d- h
window.location=url;
" P0 |0 c M2 G6 d* {* ]4 _* o) F } p7 X6 I8 b/ { d/ L, [
- U! ]/ z- [3 L; k0 ]
}
; \7 v! x: G3 B- _. ? //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认# Y2 H1 T" t. \; z" l
if(navigator.platform.indexOf('iPad') != -1)
, ~% X3 i5 k8 S5 h3 U+ _* L1 k {
: k2 f& Z" d1 R window.location=url;6 k2 c. v! \; _' ]
}, p# j. z2 n$ m
//做这一部分是因为Android手机的内核也是Linux
! B) W+ r" E/ O2 M! m5 M* h //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断1 i6 ]+ }1 Z9 p' G0 d9 O
var check = navigator.appVersion;
& h9 g+ }! M* T if( check.match(/linux/i) )
4 s+ k f& y! c9 ] {# [; B7 `# V7 `2 H
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件, T' _( _0 j! L7 b
if(check.match(/mobile/i) || check.match(/X11/i))
( b. f* A8 A- t2 M' Q S+ ^# p {! d0 B: v$ N' I) ~. }/ y0 @, w
window.location=url;! ^$ ?/ R7 B; B4 C
}
4 Q v1 }3 D; T }3 I, s; B# V% v9 n0 X" w; r: j
//类in_array函数( e8 f+ ^0 G" V& b% q. _/ E+ q& [
Array.prototype.in_array = function(e)
4 l; y8 G, i) e# o; I4 g {9 B' u$ Q' R& ^( N$ c) f. V
for(i=0;i<this.length;i++)* D r) Q( _! X; ~& b1 D" n l
{
! } |/ ?, n3 u2 U% M9 K7 D$ h- y. Y9 R if(this[i] == e)2 T ?6 u* X W# E: ~$ T
return true;1 p$ {( J: I% g% Y# `1 t
}
5 O9 c* G( G# F1 F% Q return false;
* w) x# L7 r: r9 m }
6 S6 C+ H; `5 |+ L }
( S& u% g' f* R9 Q$ ?8 w mobile_device_detect("http://m.xxx.com");* g9 \" E* R- k" k) \3 G3 T
</SCRIPT> |
|