|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。4 r2 x0 b- y$ Y+ M! i
0 [8 [ x2 b& m% _1 h- ^/ \" X! p, q/ t! _<SCRIPT LANGUAGE="JavaScript">6 L" L. l4 p. d% `/ j, w
function mobile_device_detect(url)
) O& G" T; }: J! O) Z1 G! Q {$ K4 Q! f& e# y. _7 S& M0 n& ^2 I
var thisOS=navigator.platform;
* ~0 n- R+ `" r# s4 ~ var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
* s: c5 v% r7 A" r( z for(var i=0;i<os.length;i++)
* ~6 [) C* W0 r {
7 T+ i: ` Z+ |6 v7 `5 Z if(thisOS.match(os[i]))( V% L# a9 K' z0 A4 s4 D
{ # U w. c) J8 d4 }% k
window.location=url;
' ~6 T; ~% T+ Q6 h3 E p, Q) \/ M. ~ }
) ` w0 P9 `% ^5 C
5 @ a( V' l( M) Z2 v2 s }# P# z% A/ I2 P. `, H6 g. |
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认; W& J% {8 S; r$ k) y. Q
if(navigator.platform.indexOf('iPad') != -1)
/ A6 E6 T3 `7 ~" S {
5 I; e4 [- i2 X1 n* e1 d# a window.location=url;
" D' |0 F' }$ ?' `0 L8 W) j1 W }
9 c; I3 i- ?1 d' E5 ^ //做这一部分是因为Android手机的内核也是Linux% v+ I# H6 S% n) A+ E# r
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
/ @) {( O% U( a6 v1 Q6 Q8 m: V; }+ B var check = navigator.appVersion;
8 h9 O+ m3 L9 p* Y if( check.match(/linux/i) )
% g$ l8 H1 Q7 x9 H+ I {
9 e; g9 n$ }% i8 d //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件! I6 ?2 H) ?+ n8 a3 M. b6 [& u) ?2 q
if(check.match(/mobile/i) || check.match(/X11/i))5 _- g$ O2 v* I# N) C1 {
{$ y6 Q. }) y- L3 L8 }& l
window.location=url;
- V! b# O; ^5 Z }
M9 x! f% R9 |: M! f& g/ y }
# l8 h* R3 e% @" ? f //类in_array函数
3 h) I# Y" V4 _4 } Array.prototype.in_array = function(e)
, ]- k/ F6 W- M0 { {3 b! ^ G' [9 k. H! W9 q
for(i=0;i<this.length;i++)7 \ n7 k* p% w7 o" I
{
' N: @5 X$ U3 _. e3 }! ~9 | if(this[i] == e)% p {* l% u; ~$ F
return true; y. I G& i) r3 E
}/ H; O0 s) s2 r# {5 ?% F
return false;
! `: w8 O& r. p: P, h. \& b( q }+ P) S, F- y7 Z) L- s
} ) O" |* [+ Z! [% S
mobile_device_detect("http://m.xxx.com");/ I- i$ E) f7 A/ a) H: S8 v
</SCRIPT> |
|