|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
; J j ^4 V0 q2 `5 T* i, H, ?/ L. D! f h
<SCRIPT LANGUAGE="JavaScript">0 h. R. h9 B$ o' ]2 q o: e
function mobile_device_detect(url)3 H4 W$ }; A3 G
{. R* f) C" w, w
var thisOS=navigator.platform;
9 T5 m% Q8 X+ h% _+ c var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");9 j' m4 J: C6 R
for(var i=0;i<os.length;i++)
4 C. l( S9 k; P+ M8 Z% w {$ ?4 l9 a9 Q- S2 S' S3 v
if(thisOS.match(os[i]))6 y8 h! [ `# J" [4 X: c( H$ n
{ . A' R* e% i8 I& n
window.location=url;/ e/ G/ }* c8 g' V6 J! u
}
* p( Y: R6 }7 |+ T6 m. p$ v% o4 G
9 ?/ ]: @8 U8 b }
( O) y6 b$ ]4 _0 ? //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认) M* X* p& g) Q3 T7 \, o
if(navigator.platform.indexOf('iPad') != -1)) E. {. h2 |$ P6 J
{" A- C: r$ Q; B2 _$ H. A4 T
window.location=url;
! n+ j l& [9 z8 ^2 P }
& V2 C* A t. p //做这一部分是因为Android手机的内核也是Linux, H% u/ e% n3 J
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
0 O+ u9 U0 @6 r+ b) E4 N/ N var check = navigator.appVersion;7 D1 v6 W2 M, H# e& e
if( check.match(/linux/i) )
/ }7 ~: @. M9 h6 d( C8 r( |' Z {
9 r3 o o r* ?+ B+ R$ r //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
3 H/ W J" l! O! s6 l" o if(check.match(/mobile/i) || check.match(/X11/i)): R' K3 t: s( j8 b+ H' Z
{6 o7 W8 M4 H9 a0 H# K" Q
window.location=url;
. G& E7 C' b" a0 r. q9 o1 p }
, z/ \% ]; l5 i }" [5 N) g X/ u1 i# O* I5 t# X
//类in_array函数2 c9 B2 {# z; c$ k, B
Array.prototype.in_array = function(e)
* D% j1 @& T: b7 t9 Z8 q% ? {
4 d+ w) v5 T# U- e for(i=0;i<this.length;i++)& @# Z5 E. i% }. \, l M! R
{
, t" n! d( A, \0 F: h' U5 t if(this[i] == e)
0 E; w- r/ w) [( K0 R4 f return true;
* t7 Q9 ?% y2 R# U; ?) _ }
/ N3 ~4 ~" F5 }+ s5 m return false;
0 i9 V. m" l: V2 k$ R: E }
6 m6 @/ Q0 Z4 p F& F/ J3 N } 2 P$ P4 v: P" ?. E0 z X; D
mobile_device_detect("http://m.xxx.com");7 g& _2 l0 U# N: a7 ]
</SCRIPT> |
|