|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
( @/ ^9 e2 U) l- B
& Z/ G, M0 T7 h* o<SCRIPT LANGUAGE="JavaScript">
" _ J2 n1 _% Y function mobile_device_detect(url)
/ T7 s; V) q, C* I q9 { {
4 ^; i# M- Z+ R8 h var thisOS=navigator.platform;
2 u9 [; K4 `* Z8 A2 R var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
8 {. }7 P+ f/ t$ q) O for(var i=0;i<os.length;i++)
( ^; }6 D) |( Y$ ~7 _! E {4 i! L6 P2 r0 x7 H$ ^9 o( I
if(thisOS.match(os[i]))# e+ A A0 f: B) ]7 Z
{
. S( y0 X, n( B) S5 x5 _1 p( K7 O window.location=url;* c& ~0 G8 a3 O+ y! L! O0 B6 N
}0 z ^6 Z* S- |9 y" Y
+ R2 O1 F! g S9 P9 r, {; m }
) E+ v0 b9 K, e$ ]8 K! Z" s //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认4 } j$ E% Z; j; Y
if(navigator.platform.indexOf('iPad') != -1)0 }8 r' ~, W( E5 n* W( F
{
/ Z* S$ y, _& l `/ X. i* v6 @+ Y3 E3 w window.location=url;1 T( |$ K& o$ W/ B
}
7 o7 Z( t& R) O' l3 u) c //做这一部分是因为Android手机的内核也是Linux
* x& f2 d( c, B" ?3 t' h8 V //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断8 Q* M( ?2 q8 |$ [2 w/ u
var check = navigator.appVersion;' a5 b% _" ]$ e1 r) t) e
if( check.match(/linux/i) )
2 `! ^6 N! C$ t. N {' m' S, n0 g' G" l$ h+ ~0 z6 k
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件 P% v0 t6 y8 O6 I" ^. d
if(check.match(/mobile/i) || check.match(/X11/i))+ c2 P$ f% X: W1 Y- P0 N6 z7 f
{" p, C7 e8 W/ ?; D% K: r
window.location=url;2 g2 j' @: c. |! n' k3 [; S6 W
}
$ H U8 d/ ~0 p3 @* C& C1 x }
& m" l! B1 h$ @% v9 g //类in_array函数
; d1 m" C/ Y. H Array.prototype.in_array = function(e)
Z( D9 r! c9 f {# i% P* B! c6 \' c
for(i=0;i<this.length;i++)
. H, I3 s* h& C$ }: l4 x# p* H {
" r- Z% {: D% s4 O- o; V/ k if(this[i] == e)
3 F( @0 V) i! ?* Y: |4 w return true;
) h* \6 e/ ^, F0 g H }
, L* v& `1 v. x return false;
* i6 }& w: S2 @: b }# U2 ]/ a3 l- n) I; [ n
}
, I: D" z! C# T. _( b2 Q5 ^ mobile_device_detect("http://m.xxx.com");
: q; L( |% H$ ? </SCRIPT> |
|