|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
% v! B' d n+ K9 n! e$ Y- R/ J2 m
<SCRIPT LANGUAGE="JavaScript">+ y& A5 ]* L: F" e' m& P8 }3 D
function mobile_device_detect(url)
: d% D8 s6 d z {
0 m0 u6 B0 [! \* r/ s8 G var thisOS=navigator.platform;
* q. O: e( d. \ var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
; h( ^$ S# Q0 Y. n3 c0 c% L for(var i=0;i<os.length;i++)
: T/ j; r; E3 [! m+ M/ Q {
: Q# j% I; V" \4 ^ if(thisOS.match(os[i]))
8 V6 d6 w& ?" J4 w+ x { # i! M6 X" Z* h7 F$ j3 J
window.location=url;+ U$ r( e7 f! a
}
' s% R1 A5 W9 ]+ a% A/ L 1 p: J- t! _7 _' o. Q8 d+ X
}9 }+ c7 H( F: S R% z2 x
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认4 a$ s' z5 `+ S' H4 `3 ^
if(navigator.platform.indexOf('iPad') != -1)5 M: d L& M+ }9 R8 ^
{2 J1 ^6 ]& O" ~
window.location=url;
9 } V2 P: E( o* a }8 y/ Z7 p. b0 u( x, G# H! o1 @ ^
//做这一部分是因为Android手机的内核也是Linux
$ h8 ^" k( T, K c //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
1 ]' {, C6 d% Y/ e var check = navigator.appVersion;
" q9 u! H+ o9 m) t2 C4 n if( check.match(/linux/i) ). `/ |: S$ w* B# v% R
{4 A# N5 e- N4 n% E% f2 q6 Z
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
5 d+ V% @5 j0 J4 x if(check.match(/mobile/i) || check.match(/X11/i))
3 w0 Z1 ]! p; w* k {9 Z, _+ k3 Q$ [/ v. h2 L D5 }
window.location=url;1 q. ?, y3 |* Z- x: a% {
} % F% o8 @: V7 y* H' p1 U- P
}
& x p! L5 i/ t0 R! u0 s //类in_array函数! i$ L4 f& D+ L6 k6 d0 A
Array.prototype.in_array = function(e)% l- G; _5 v9 g. e
{
2 U$ H; B% u ~2 \ for(i=0;i<this.length;i++)& x2 x2 v' @6 Y E# _; x
{- J. ?2 u9 ]+ l0 |" \, q9 C
if(this[i] == e)
/ ~! ?# r4 H [: b return true;
+ K1 \ y+ S e4 m+ z, b* ` }2 N: l2 {9 u4 b6 \' N6 u9 U& ]
return false;
; m- X" v8 s) }6 j6 z5 c }
" j* x( T) i) }7 B7 s1 Y& j5 T } 3 K' y7 @- k* Z1 G6 D' m2 K' c
mobile_device_detect("http://m.xxx.com");& }' W( T% s+ p
</SCRIPT> |
|