|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。: y2 G# b* q( {: t
' B, y! F: {1 I/ Q
<SCRIPT LANGUAGE="JavaScript">- h3 e0 @7 g6 B+ ]1 G
function mobile_device_detect(url)* j& J4 \, j: h+ V
{; }! @8 p6 Y$ O( Z
var thisOS=navigator.platform;) _1 W% n7 E3 r) 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+ r8 M* J: T; \8 i8 ], X4 T for(var i=0;i<os.length;i++)( ^$ N: } C1 r# [
{! [) \* J1 A7 ~
if(thisOS.match(os[i]))& B, F$ c# L, v5 a$ y
{
, }3 i6 W2 n/ d1 A2 b& Z# z7 ^% }/ N window.location=url;$ O5 g+ k0 J1 m" }! o2 q) f T5 B0 l
}
3 I( J' I# d& [% c6 \) ?( A; m
& t: I) \/ R+ T, s1 Y }
6 b- q8 q) X5 L3 j/ E2 k //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
* A9 |3 ~3 ?* Q if(navigator.platform.indexOf('iPad') != -1)
( |/ A4 r9 o+ b6 c {
6 g- f" A6 E9 b. j! p" e window.location=url;" z, K+ a) ~( F; ]
}# C1 ~" p7 j) J$ f# Y: w h
//做这一部分是因为Android手机的内核也是Linux
- R9 L/ u9 q. V! }0 ? //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
' ?. a" H. Q# O6 e" [" i7 g, e var check = navigator.appVersion;
& C+ D7 v* x! U; [6 E7 o if( check.match(/linux/i) )
% E0 U+ N6 ?* A: J {
9 f: ^/ H* U( _2 e& j# S2 B T //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件5 A4 p' Y. B$ ^8 a
if(check.match(/mobile/i) || check.match(/X11/i))! [+ Z( _* O0 d' e# ~
{
" P3 a' g5 C) l3 N window.location=url;
. E2 \- ^3 l( H4 c5 i( G' b/ y }
& }8 Z/ o6 D" V0 [$ h& j2 A% O. U }$ j, }4 r& K5 T. [ t7 @
//类in_array函数
y; L3 ~+ A @0 M; N! t1 s Array.prototype.in_array = function(e)4 _ V' L! M3 H4 S1 G8 a$ i3 p
{
6 U5 b* Z2 Y: e3 v* w \9 ^' g$ X for(i=0;i<this.length;i++)
$ s( ]& l9 a1 R4 Z2 v6 s {. _& E# ^ S! ^ t: A
if(this[i] == e)9 j* }! ~( B: ^! U: D2 r. K; V. m8 S
return true;$ F, |0 G" W6 W P5 Y
}' Z7 Q( s* |% s
return false;
4 ?. w/ G. h3 c4 r" E3 H# [+ Z }
0 \ N2 S2 K% O7 t" U/ Z D }
# Y% i) W/ y2 F8 ] mobile_device_detect("http://m.xxx.com");: O% O; k7 q8 ~. y) p. V
</SCRIPT> |
|