|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
, s) i: C9 X. @0 E8 E8 g, R
6 o3 a. f7 I. W: M0 s# B<SCRIPT LANGUAGE="JavaScript">
+ M1 Q `* s" s function mobile_device_detect(url)9 l, Z2 `: I0 |, U, A M: K( v" [! T
{$ i6 P' b5 x X6 M/ Q- ~# G
var thisOS=navigator.platform;. C. \; l8 B0 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");
$ F6 g9 a! ]5 s8 ] for(var i=0;i<os.length;i++)" z0 ~) p ], o. r% W
{4 T, t% n: n8 e. [' E$ E# r
if(thisOS.match(os[i]))
( n+ ?! j g/ x1 [5 {# ^/ u {
4 d; B9 F. P' P. n% z9 ^ window.location=url;1 j& ?$ r1 ^- U4 r
}
5 ?& V- l$ v0 _/ G: S" k
% l' ?6 b- U% R7 e D$ I }
" @5 k6 a; c: }# j, L //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认/ ~4 z5 `% I/ O' N# Z; j( E; i
if(navigator.platform.indexOf('iPad') != -1)
: N% c8 ]' ?! ~0 L p {
4 H* N& H: V4 k. P9 g window.location=url;
& |" N1 w3 {4 P3 F: n4 ? }
1 Z: I$ w1 _/ O //做这一部分是因为Android手机的内核也是Linux) }! k5 ?7 I9 \# k5 ]1 P
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断# e4 l! a* \: ?8 c- P/ J
var check = navigator.appVersion;
0 j5 o: p% ~6 h5 a; ^ if( check.match(/linux/i) )4 y* r6 _4 y% n1 B0 U9 e) S) }
{. J# e" P. S; h! ~$ Y/ x
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
) |2 \" a8 Q7 h4 G3 u if(check.match(/mobile/i) || check.match(/X11/i))2 f0 t* ?3 s5 ~6 ^/ A
{
1 C& A! B4 v6 ]6 `% }1 E window.location=url;; N7 T" g/ p. p3 b
}
+ ^& C+ ~; q; n2 m1 j }. E1 F1 z8 C3 R# N( u: a0 z
//类in_array函数
. y. \7 ]$ j' K* X% |& ` Array.prototype.in_array = function(e)
4 e2 I% T& T7 x9 s) K {6 ]% x3 V9 v L$ V0 I
for(i=0;i<this.length;i++)3 E+ |$ |, m' e. t4 ~
{
/ Q( u" _- o) @) e if(this[i] == e)% E( k% ]: H4 V$ k; V
return true;9 d. b0 W# r/ o# v& K' D
}/ }/ n# }9 W4 q q
return false;! L0 K) U7 e* r @
}- Z. ]. I' S1 [" _. a d
} - h% T. P5 S6 |6 k8 E
mobile_device_detect("http://m.xxx.com");
3 q& _- V7 y3 c8 r# A6 W4 u; O </SCRIPT> |
|