|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。/ D9 A5 ^9 s6 B: D* e% {( S
1 t" m7 ]# N# V+ R& l<SCRIPT LANGUAGE="JavaScript">
c4 [, e* J& r& Z) F; e- y function mobile_device_detect(url)
, s0 J- W- O( }; i) n: r( } {- Z; A- s5 k! m/ A% y/ z7 S& A$ @
var thisOS=navigator.platform;
. z9 G( t6 e, L( s; b var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
: Y5 q/ u; p' {' H3 v for(var i=0;i<os.length;i++)- e$ R8 f6 b" o* l
{
9 Z: L5 r: `$ R4 ?2 q if(thisOS.match(os[i]))
2 z& O( L. W4 b { 4 Y) c0 s$ Q4 y; ^( r
window.location=url;5 J1 v% a0 |# a) n; [
}+ _( k' G; M. L7 x8 x
0 O3 B0 A7 [7 Z! f$ e3 B
}
F" O7 h! P' o* k //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
. \# M, E! s2 q* B+ s if(navigator.platform.indexOf('iPad') != -1)
0 R( q5 N' ~" U" W! p {) x: `2 d( }$ I3 W/ I
window.location=url;/ [0 t0 A! s% |( o5 E/ j0 ?6 V, ?
}
4 e7 p2 j- v* A! u, U //做这一部分是因为Android手机的内核也是Linux1 F) t( \5 t) o0 Q* J
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断( B) X5 i2 h, B j
var check = navigator.appVersion;! R8 c/ F7 W; F; o$ u8 B9 Z
if( check.match(/linux/i) )9 ^, Z! @ ?' }# E- }4 @5 @! ]7 g
{( q" }2 l6 @, p5 H
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件$ K- h/ H& B( z+ e
if(check.match(/mobile/i) || check.match(/X11/i))
6 S% Q5 Q+ r: _# [ j' P5 w {' p8 g5 [* L( E, I, T" d
window.location=url;
$ ?* j7 Q, t) a- Z7 g4 p' B }
* Z; M2 r* P }8 @) V! J }
u% e( L; t h3 l9 v //类in_array函数
/ `, [/ f/ O: U) j* [9 m Array.prototype.in_array = function(e)
. z3 t+ q6 \# E- E' Y {
7 I5 S) x$ M: t7 ]5 J% Z; S# ` for(i=0;i<this.length;i++)1 n$ W5 t- L/ Y3 Z( d
{) T% x1 q: m. ^" ]0 m" t/ L
if(this[i] == e)! w1 p. t! j0 c
return true;) e$ R' L7 N( Z) g9 e
}
8 _' n" n: ^2 [6 N$ I5 a return false;% Z4 i( U$ i. V7 R* P2 p
}* n+ P4 ?0 Y! ?5 R6 |
}
' t* [/ c1 v) p5 `" w- A) v0 X' F mobile_device_detect("http://m.xxx.com");; C% o! n c& h& s) R; Z
</SCRIPT> |
|