|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
! w1 V1 W2 P% l2 f- K4 ]
3 U/ U- X% w. M3 s<SCRIPT LANGUAGE="JavaScript">
* P: O7 n7 ^; T+ Q/ M function mobile_device_detect(url)
# [' o+ P6 @! l9 s {) f' i5 v6 ?% K" I! d
var thisOS=navigator.platform;
$ q/ E, ^ v' H9 |; [# ~" g var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");. V% g% q, x2 L1 h; s
for(var i=0;i<os.length;i++)
c: H( _& ^! d7 ] {
v5 o: \5 a {: o# ~. o if(thisOS.match(os[i]))
. i O- P7 g$ O { " U/ @) c) r* Z+ O& z, O
window.location=url;
T) Z' V* }+ K }/ \3 ?# \2 c" ]# c- ~, i6 a
& [ k3 }, Q' m0 k" b }* d( n' I" e* F2 w/ u2 A
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认! B5 O6 L$ ]6 M4 ]! K
if(navigator.platform.indexOf('iPad') != -1)
; Z# H4 E. R2 x8 v0 b {
; }0 N# `' i1 k% E! T( h5 a window.location=url;
, c1 p; n9 M, E+ o }
6 B; n, j* w: _$ H, _5 Y5 Y2 G //做这一部分是因为Android手机的内核也是Linux ]/ M: j5 j. {3 m* V
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
5 |; X5 D6 g3 p* U: W. Z: r var check = navigator.appVersion;/ \' J( @" R7 O3 B
if( check.match(/linux/i) )- [" z" z! D" M- x6 n U% H7 b" Z& x
{
+ [2 s! `% q0 Z3 `. Z5 K2 d- w //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件: z' ^% h0 l! X) p
if(check.match(/mobile/i) || check.match(/X11/i))
) Y% F- |5 O# F( B* q {0 g4 |/ T' x; u( y6 y8 r# P J6 E9 k
window.location=url;
+ r# I0 t, j4 a& a, u1 M }
# O3 ^3 r0 h# H) ]" X$ b }0 J) e1 x8 A2 U G6 W
//类in_array函数
. v( C: L) [% @( d$ c2 ?0 u! Q9 G Array.prototype.in_array = function(e)1 G* V9 _3 f. {; _% T D0 ?6 L
{
+ P4 [& E) Q1 G5 J; p8 n for(i=0;i<this.length;i++)% [$ L! P) N! P4 Q0 m1 X
{- g5 d* L3 y+ r
if(this[i] == e)
& F% }* n) D5 O5 n return true;
9 {" e8 s0 d& w }. u+ s# f6 \% S& ~5 T4 u
return false;
5 o; t& r* b# i# c. \) h }
# D- n" t) V* {) d5 s7 L8 m a5 E } * y- p& s# S- j& N$ J2 ]; R! N
mobile_device_detect("http://m.xxx.com");/ P2 o" u% A4 X* o! i Y6 r, e
</SCRIPT> |
|