|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
( R- L4 I D0 @3 O' d
0 h6 d4 r+ Z8 g' A% J( t4 i<SCRIPT LANGUAGE="JavaScript">
( l& A- J6 D2 A- m: v3 C; Y function mobile_device_detect(url); n2 Y2 r' }& Q$ }( L6 z4 F
{+ Q1 O3 y4 k% Z g/ z) q
var thisOS=navigator.platform;
9 I( p2 ^0 l* b7 G( @& @2 ^ 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 {( E- p) Z+ o' F; e( D5 L/ C J! s% n: X
for(var i=0;i<os.length;i++)
/ [% R: j2 ~; A Y {
( f; f) r& ?! E/ f if(thisOS.match(os[i]))
1 r2 |5 Q& w2 @ P- i* ^ { & m8 _6 i6 k5 G7 G
window.location=url;; b( d* C) C9 M' ^0 {3 i
}; U0 G# A" O2 }, ~& X
' t5 V* ~0 p( q9 |8 r }
P$ F% T; Q" N n7 l/ z% v4 S //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
$ i5 x* d7 _; H9 D8 t7 a if(navigator.platform.indexOf('iPad') != -1)8 F* t" h1 f+ t! ]* R" L6 b
{
) m8 i) `! [5 V window.location=url;2 z7 [# p9 l5 ^2 }( b ?5 D
}2 Q: m3 w! ?. G! j3 s9 t: g: x7 r5 b
//做这一部分是因为Android手机的内核也是Linux
4 T3 u- N7 o, F4 f2 j# B$ h //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
0 l# X! _" Z, C! X" _ var check = navigator.appVersion;2 e9 Q5 u: o+ J: p
if( check.match(/linux/i) )/ Z0 H( n( _3 e
{# G) u5 \: R" d1 k! O3 I9 @! H
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件/ H/ t& ]1 T$ g' T5 {) f
if(check.match(/mobile/i) || check.match(/X11/i))& \( X" D; j) d: N3 `* Q
{" L2 O, K% y) \ q+ ] D2 {9 x* B
window.location=url;
1 x+ e8 Q/ G' o! q }
) e; L. [) O; @" g6 d4 a }* E9 b. ~" S6 p( S, @2 p
//类in_array函数- i! g0 b5 B R R
Array.prototype.in_array = function(e)4 i7 M; r' o% T
{
- ]* D2 n+ J* C4 d5 I) ] for(i=0;i<this.length;i++)
# q- s# X7 t6 Z- h6 _/ s2 n* X& m* I; | {
. K+ i8 O; e4 K+ ]9 S3 a5 a if(this[i] == e)
8 S# Z5 y4 ]/ M, H2 y* G" @ return true;
+ n2 Q S$ f. r) x8 W9 t( { }' [2 i5 v% Q+ H$ q, s
return false;
9 ]6 d5 N1 P& q, E2 ?0 w9 F }
) N* ] W y% }' M& m0 @2 a } 4 O' M- {3 }' R! c2 c" J4 y
mobile_device_detect("http://m.xxx.com");+ A6 C P! J2 @6 [# m' C. v
</SCRIPT> |
|