|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
1 `% \/ t' t- n; I `$ f" ?/ j. M+ Z" b0 v+ X
<SCRIPT LANGUAGE="JavaScript">
% p- b( W, l- A function mobile_device_detect(url)
5 L2 u. _# l7 p: \" l {
+ ^& L1 h1 s4 _ var thisOS=navigator.platform;+ W- k u4 T2 |& p
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");! |# b7 B; b8 j" n' a
for(var i=0;i<os.length;i++)) q7 A4 T& e* J. r. \% |+ G1 J
{) o8 k* q; N) F$ }! l6 ^4 Y- f
if(thisOS.match(os[i])) B G4 ^' L: h
{ 3 p5 ^3 s; v; c* o- Z& U1 n% N$ f' f
window.location=url;* G; c9 ^6 O1 J* m+ i% {
}
: x8 p$ I. b y2 J- w0 O. _3 Q& O
2 h1 E% B$ c- ]6 C, T }
* v) \9 k8 a0 e% ]1 B9 @! k //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认9 _" k1 _ g' g2 W
if(navigator.platform.indexOf('iPad') != -1)7 ^; A J4 h* s% Q, `
{- I7 n- m3 }" Q
window.location=url;
$ `0 W4 z0 r& P( }& t0 `7 a3 r* o }; w- k& `) z) C/ G0 s# _
//做这一部分是因为Android手机的内核也是Linux
8 U5 E& @. i. y+ c6 H& \% T //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
/ q% p% X# r7 w, X0 V var check = navigator.appVersion;
/ h6 n7 n7 [7 ] C1 O8 l. V* u0 H if( check.match(/linux/i) )
4 z5 V0 O) |; W0 O$ z: Y8 C {2 N; n3 S) d! W" r* _ I% [$ t
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件6 P/ j5 u& `- x/ [+ R; h; C" n
if(check.match(/mobile/i) || check.match(/X11/i)): t. ^7 t1 S9 |, E8 o
{
2 c0 K- E+ P0 y3 B window.location=url;
4 I J* l8 _ u3 u8 [8 Y }
, ?/ d/ |7 U" v8 a }
2 X# N" n6 W4 g: r //类in_array函数2 }3 i% Y+ v5 o( P+ V
Array.prototype.in_array = function(e)" o" |* H' N% h) } J" q
{
- t* M! w- U1 e for(i=0;i<this.length;i++)* Y1 w7 b5 c o
{
& _5 N* Q9 z* V# G4 s if(this[i] == e)) W, r8 H% ]/ |5 R2 N+ A- U+ b; `
return true;* X2 ^) M; b5 h, a$ |
}* G$ S7 W: O% m7 p4 K
return false;9 |4 x7 t* V$ o4 \9 v
}
: {; s, w5 _2 U* e1 d# O }
' `: ~! t! q9 y k& f; z ~2 q. X mobile_device_detect("http://m.xxx.com");
% L; s# r4 `% |+ o. v </SCRIPT> |
|