|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
6 F' C' H: `' M8 T; S$ v5 F* ?& R- z0 X/ ?! l
<SCRIPT LANGUAGE="JavaScript">
8 F: R, _# l( ~0 ^: q function mobile_device_detect(url)0 F: Q9 v/ D+ i" |2 E& N$ e
{
; B& R5 `% W: g9 M5 X var thisOS=navigator.platform;9 j- M/ A1 u3 q% {$ z) v
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");; M" n: Z$ y. o( ]" h2 z1 e8 T
for(var i=0;i<os.length;i++)) H) J" w* T* G2 W, N q: @
{$ s) q0 u. V4 V* i
if(thisOS.match(os[i]))
& M! }1 A( F% _; M" a { v2 Q% E! j" e, n: X
window.location=url;
: a* E) e$ M w" j# O% ^ }% m: ]" d$ g \+ d: S* f! U
% G1 r2 G4 a# K( @ }" f0 M, j3 H9 D
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认$ J/ j: r3 `$ q% O$ S8 V7 V4 }* E
if(navigator.platform.indexOf('iPad') != -1)$ }! N8 f5 x$ B# m8 J' f$ g' Y
{
2 F( M' {! X" d6 z4 T1 Y9 o window.location=url;$ u. C6 w% ]9 J- M& O
}$ \ E \, R" W" w8 c
//做这一部分是因为Android手机的内核也是Linux
# M& v; `: H' [3 o7 I //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
, q& r" P2 e& |. ]) L4 P3 {/ j var check = navigator.appVersion;$ L. S( z' E4 @ c+ j: H
if( check.match(/linux/i) )0 a: T' ^/ k/ E2 _$ L) q
{
2 w/ B& g! B- o //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件- V7 K7 a. q6 g% j% [
if(check.match(/mobile/i) || check.match(/X11/i))
0 s& I; O, t: [3 Y V6 o0 y# I {0 X) \* U* Z" a' _
window.location=url;
/ t( x. ]3 g" j5 q u } ' H3 R9 F( F6 F+ h! X9 F
}8 C( Z3 x& V! S/ P
//类in_array函数
2 ^! n9 Y0 P4 v4 W Array.prototype.in_array = function(e), _& ]) E. P; w
{
- C! E( r2 e& Z8 k7 n for(i=0;i<this.length;i++)8 B1 _4 G" [; e. C7 F7 V7 q
{7 J k* [9 {, r' \; F. W
if(this[i] == e)! q5 a3 t' ^0 h1 G* j; _( v
return true;8 d. }; Y' t3 V
}8 p0 y' R- x u4 n& i5 P
return false;' e& b8 a2 ^( s$ |" A
}2 _7 Y3 A2 Y ]5 Y7 p. a
} 5 G% Q7 U/ @0 p5 c0 f( L9 {
mobile_device_detect("http://m.xxx.com");% K; L( r# s4 Q+ v Z
</SCRIPT> |
|