|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
# G8 r7 [* f% G& y: @5 g6 ]$ n
9 q; r/ y' t5 c, |, h" S8 _<SCRIPT LANGUAGE="JavaScript">
- d* p) F9 D. a# Y% ]. o function mobile_device_detect(url), t/ Z+ H; X5 D& L$ \9 T2 X" c
{, X/ T0 f; v! G. M% k
var thisOS=navigator.platform;
$ N' s+ q$ s h2 t var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");6 t0 ~" v3 f/ s5 ` O& T+ m
for(var i=0;i<os.length;i++)
q% A: u8 Q% \ {" Q* j- p L9 B# j& w+ Z0 R' q3 T
if(thisOS.match(os[i]))1 u. z9 N" f* ~' T/ I) R. c
{
! B, c G/ Q; b3 o, o6 r window.location=url;
' j$ ~0 o1 b- q9 u' Z }
a+ `6 _2 g1 P* {
0 J: k2 [% T1 q+ B }
4 l9 i8 e4 N2 [9 M% i2 A+ B //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认0 ` k* H$ H4 m- n
if(navigator.platform.indexOf('iPad') != -1)* ^/ w4 i$ a: Z
{# d. y" G- f! A) d' |8 Q
window.location=url;
% P& X# g! g- Q0 ~! C }0 y% ?' R$ e# i( \7 Y9 |& w
//做这一部分是因为Android手机的内核也是Linux& p e. h7 Y8 F6 `7 f
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断: a1 {( u, W7 [) K% x9 M4 I3 e/ f* F
var check = navigator.appVersion;3 C5 i( k5 Q: v0 u2 c
if( check.match(/linux/i) )! Y. P; a" K2 x
{0 O$ P8 |7 M v. L# W; }
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件( s2 C7 ^9 K* J4 f
if(check.match(/mobile/i) || check.match(/X11/i)) Q# @, }: K! Z7 f2 X
{" _! }4 R* L& T& i: y& W5 k
window.location=url;
8 V5 T& s7 g- Q4 ~$ @) q }
$ g( d* Q+ @5 @! E# ? e9 U }1 a# }! C# z, G
//类in_array函数5 B$ Z8 C. Y5 y5 _3 H, c
Array.prototype.in_array = function(e)
5 Q( V; _! G) y# ~3 s# T4 \ L6 b {1 @# a# H' R$ |" Z
for(i=0;i<this.length;i++)& \5 u1 R* n- o7 {* t$ f# Y
{8 W' O |8 y' f3 d1 Z+ f
if(this[i] == e)" ]+ [# _! o1 r4 T- l2 G
return true;5 k& g' e( {3 z5 n9 {- l$ j! c
}- r+ E9 ?6 Y2 C
return false;8 F* T' a/ R |6 x! ~8 r
}
" _: f0 u1 O. Z9 l# z" y8 c } 7 c- `5 e7 o O6 i, R9 D u
mobile_device_detect("http://m.xxx.com");" i [. s; O7 P' z; ~
</SCRIPT> |
|