|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。- g+ Z1 c: }7 c* }6 y/ I
. w3 G( j3 \9 t) V" b2 x) c0 E
<SCRIPT LANGUAGE="JavaScript">
% f6 p! d0 m' T: e- y. s, f function mobile_device_detect(url)9 S( q3 R) N: V5 ~, T! m2 }
{
4 M% y( B! X* I6 Y2 Y var thisOS=navigator.platform; Y2 i" G$ ?# ^; h
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
' \/ {) \( c- r- I: p8 ` for(var i=0;i<os.length;i++)
2 Z& \* I6 h H6 T6 J {
; n& P; V: K* P7 @6 i" s4 @+ X if(thisOS.match(os[i]))* G* [' b6 I$ J% A6 n
{ ( u; D; X! D( P/ @, G
window.location=url;
9 k/ R% K" q; m/ a }
$ T: n' B3 i& e! c' I5 d9 `
1 j. H7 R- F" V( H& q, m( \. N6 x }
+ g0 F+ @* a8 q3 u- n1 w //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认2 Z c4 ` K" X4 k5 f1 A$ ^
if(navigator.platform.indexOf('iPad') != -1)4 ^8 s9 k1 G9 j8 G% G% ~. u, H; B
{
7 l/ |! |' L3 h+ j$ Z% ^( X7 y window.location=url;
o% f; k h# Q/ k5 X. ^2 d3 u }# n- \2 L$ Z, |- { U/ y
//做这一部分是因为Android手机的内核也是Linux- @ s2 B, S" G; j( D! b
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断) e3 g s' Q" h" q: {6 r6 _0 z
var check = navigator.appVersion;
) p- m( f+ \, L9 a: V7 d if( check.match(/linux/i) )
: ~$ m' c, G3 e! B2 n( P- E {
5 a1 C: Q: K, S8 i/ C //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件7 N1 P/ E- ]) t; O2 F
if(check.match(/mobile/i) || check.match(/X11/i))3 c! y4 Y, |" N, z4 R
{. C- f" H$ P6 h% U7 o
window.location=url;: [( [6 I2 [7 ]3 H. l; U
}
$ W7 @9 p+ E+ t9 _7 ~ }
y. a6 p+ n8 W2 m7 B$ w' k$ b' e //类in_array函数1 }- `( {# K8 J3 J
Array.prototype.in_array = function(e)
" x3 v8 [4 P _' X {
: \( O9 L3 R& M4 J+ ~; [2 P9 ]' t for(i=0;i<this.length;i++)7 ]; H0 d& I$ _+ }' r% c
{: f/ K( Y0 s' W9 B/ i( P
if(this[i] == e)
: k t, d; e* H/ T return true;
! B. |0 e9 t% `& z' H, j" b8 s x }2 R3 J2 G& c* }5 z
return false;; ]; }' W& p7 @1 m
}
$ P$ [! H5 X$ F( z' B% R8 n } 9 v( I x& f4 `* K) R
mobile_device_detect("http://m.xxx.com");" q/ |9 ^9 q/ i9 U; |. L6 _
</SCRIPT> |
|