|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。% e# c$ G' B* ^. n' s* i% L
t+ i6 l8 {0 R- q+ O2 l<SCRIPT LANGUAGE="JavaScript">) u1 |! w# J% ^1 s' A$ B
function mobile_device_detect(url)
+ y' \8 H* \: N j9 Z. i {( F/ X6 E9 {/ [# _6 V
var thisOS=navigator.platform;
6 L' G% {: E4 K& x& b0 K) _' F var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
2 k' @, t1 c. @) I: X* ?! q: | for(var i=0;i<os.length;i++)' Y0 c) v" i4 o3 G6 N& [; |
{
9 U( e5 C0 l9 @* O7 s% } if(thisOS.match(os[i]))
{, e0 v* C+ j! t {
% j2 l& w T0 V4 c+ H* W9 z/ D' e window.location=url;
) f; a! F) o! @- z6 j, @, s& } }
8 z4 U( {% \5 h& w# ]
T5 D. U9 T( Y }( v7 u5 ]* [7 Z" h7 }
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认0 Y) x% G3 I0 V2 t7 V
if(navigator.platform.indexOf('iPad') != -1)) z& Z, I" B* z2 A
{) H: A' T! J2 l Z0 N, v
window.location=url;
a: z/ t- j0 W6 d }/ X; _$ F2 f2 ~4 U. W
//做这一部分是因为Android手机的内核也是Linux
& H6 W8 j* E! ?/ R4 M //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
6 x8 M+ D5 ~( U4 j) @ var check = navigator.appVersion;
0 K, K8 ?: m0 _7 t2 ~ l if( check.match(/linux/i) )" a: t* y7 X: {' U- \+ N
{) e& _/ I" r, R6 A( G
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件! {+ G; c. V" s0 f' v
if(check.match(/mobile/i) || check.match(/X11/i))) D6 M5 d& T0 D6 S' G" `# d5 \
{: `8 I( R" D" `5 B! ]3 O3 u3 C1 h
window.location=url;- V+ X1 C8 S4 [6 H4 y6 x( s L6 l
}
, e% g8 Q. \6 Z3 D' n }
5 p; m9 ?1 L1 T8 I //类in_array函数
( y( `# F8 L, P& x8 ^, r5 C Array.prototype.in_array = function(e)) e6 i. J' ~4 j
{" ~( w5 F. `% g. C
for(i=0;i<this.length;i++)
- o- f- n' n, D- C% t) ^$ W O { F( l1 \: d; Q
if(this[i] == e)
: K7 |& ]' C; n" r9 Z/ ? return true;
) o0 W+ l/ E _, V/ c# b" r/ X* } }
* s# p, X6 W3 J# P# f return false;
( R) h" {! a$ J9 O3 L }/ ]' u% a+ Q( B) }* ~
}
1 i- u$ s+ c' r; a( P mobile_device_detect("http://m.xxx.com");
7 K8 M- }( }. O% U </SCRIPT> |
|