|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。9 k+ i9 f: Y4 t0 h
! G1 i" S1 ]# r6 a5 p<SCRIPT LANGUAGE="JavaScript">+ K9 S+ r8 B- ~; H
function mobile_device_detect(url)
4 \; a+ R: T" m( _ {
1 ^0 M$ `8 Z* m9 m var thisOS=navigator.platform;5 R. G6 x: Q3 v" x7 j
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
1 F3 I$ y& x" }; ?+ r for(var i=0;i<os.length;i++)/ g& G Z0 O$ o8 N3 x$ A
{
& b/ x/ @5 X3 G( ? if(thisOS.match(os[i]))) x$ C. y7 X" z& b' d
{ 0 w, Z) E- d% F) A
window.location=url;! p( c9 Q4 Y* p" z9 c7 B) s* l
}0 V6 P+ h9 x. }2 k! }0 U/ o O
* Y9 E6 E- h5 f; n9 V* V/ V% J }
" q c! Z# {) w& c* p //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认; l, ~" ?6 D# C1 e7 Q
if(navigator.platform.indexOf('iPad') != -1)) I/ y: H. c. r+ ]0 s
{ W5 {3 u M+ f8 D% C* ~3 Q# l* ?
window.location=url;
0 `3 ?% u L' Q, m {, M; w* v }
- [5 z. V0 L4 T) |7 X //做这一部分是因为Android手机的内核也是Linux
7 f: U# d u+ F/ x" l //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断* t O" y5 d$ Q$ k& ]* I
var check = navigator.appVersion;
& V$ s0 [( R8 B1 p$ ~6 m if( check.match(/linux/i) ): r3 v, [1 s% h& P0 b3 T6 w
{- `0 p7 K' y# l% E8 w1 V5 h" ~
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件3 \$ F% }$ j+ H% _- ]
if(check.match(/mobile/i) || check.match(/X11/i))( }, F6 M+ P1 R* F- }: v$ B8 g T
{ w4 u& [0 W* }- n- n
window.location=url;/ l+ k! d4 u& N& `( F5 b% ]
} 4 A. D! k$ Z0 E3 c
}
0 H( Y, l' W+ J) Y) E# F) G //类in_array函数
( A, ]; @6 F1 ]: e* }1 Z# J Array.prototype.in_array = function(e)
! X) i; q/ i, P8 U0 I {& P3 `" m7 h1 l
for(i=0;i<this.length;i++)# n' i1 ]& K$ @# a$ e
{- ]$ ^; _3 T& S2 M1 U/ B# w$ C
if(this[i] == e)
% z# \ L9 |) Y5 M9 z( V9 ?( ? return true; t0 u6 c# m' J: E8 @
}
1 Z7 S0 A8 V2 A* k- a return false;
. Y! C {. g4 P, w1 d }* z' d) K4 h, n e, t% r8 u
}
8 ?1 s d# c# Y mobile_device_detect("http://m.xxx.com");+ @0 O' y2 _& O+ B
</SCRIPT> |
|