|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
* w9 u' _0 W# I2 a- R4 c# T+ Y! @: `9 \9 ]
! Q# ]9 f6 G2 D0 m: e& K<SCRIPT LANGUAGE="JavaScript">
, X' K( q1 r+ D4 b. s' n function mobile_device_detect(url)( n( e( f9 s" O! [/ j, L
{4 Q7 g/ D0 P1 o6 p: }
var thisOS=navigator.platform;
3 v# W# e5 s7 W: A4 K- O+ t$ e; V var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
# c4 P4 u- f$ e3 f for(var i=0;i<os.length;i++)
1 Z. m2 B* F. l/ J% Y" Q* j# b {
d) d# `! W, C; ]1 d if(thisOS.match(os[i]))7 M& _& E$ D0 ]( X5 C+ a7 d6 b
{ # \' E' T% }* [
window.location=url;& V+ o* w( c6 }8 x9 Y/ h
}1 p# h, n9 U0 O4 ~; c
' a4 p" N' x* H1 B }
* T# Q5 M1 m3 ^% R //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
& ~# k6 T) g. l0 M if(navigator.platform.indexOf('iPad') != -1)
: i9 y+ P( Z- u4 S9 @$ `* p6 U {1 n" x% ^) U" h5 E6 [+ ?$ a7 D. \
window.location=url;' Z+ R/ G' J/ I+ f5 q' H1 |
}
3 {: j0 \4 o- ?" U/ Y1 | //做这一部分是因为Android手机的内核也是Linux" n9 T" J& M3 ~( V
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断- w" b) c! N# E: r( ^7 Q
var check = navigator.appVersion;6 t7 j% u6 h, ~) z( H% L6 R
if( check.match(/linux/i) )
& h' A/ N1 ?' Q5 u X2 E/ P9 ]' R {
0 i2 D0 T5 j# J2 m$ |: n //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件; f0 J; B- [* P
if(check.match(/mobile/i) || check.match(/X11/i))4 j9 c# M% L: k0 M
{6 ]( B6 C7 d" ~2 z* P& O5 A
window.location=url;
* z: A4 U& e) c) m; E }
5 D P, J8 u) c6 T4 P6 R$ Y9 V }
7 q& c6 b- h, Q, f. u. k* r. c //类in_array函数3 ^" c0 B" n/ ?: j/ `5 X
Array.prototype.in_array = function(e)
+ a0 S3 C" V8 B {. Z! Z( Q+ G( q' L
for(i=0;i<this.length;i++)$ S8 ]2 n; _) S, l2 r" n
{8 @$ C* X+ K3 ~5 W0 n
if(this[i] == e)
1 i1 @. K7 B8 T1 r/ r return true;
8 H# A' s; D" L4 p7 r( b; j* n }
! U' b* C- U* V5 Z return false;# |+ h* v$ B1 ]7 }# g/ P0 r/ f0 [
} E* W% _, E$ v3 q1 ]
}
: v/ z& O# c/ e% O- O mobile_device_detect("http://m.xxx.com"); G z, W j9 l. Q" R" d+ ^
</SCRIPT> |
|