|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
3 d# ~& o k/ k8 x T5 j* b7 V, M1 D0 A
<SCRIPT LANGUAGE="JavaScript">
; V ?, S4 m! Z6 q function mobile_device_detect(url)
) \5 v( R9 J. M" i6 d {
& g/ G4 s' J. Z. f i var thisOS=navigator.platform;1 H+ V7 [. `; V- I- U
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
. ~8 i. e7 J) Z) o! I/ z( Z" R for(var i=0;i<os.length;i++)
3 F& k. k/ ]8 v+ z {
4 T4 h- H' E, S9 Z4 u if(thisOS.match(os[i]))
( C5 ]# j5 j: {/ w; I {
; b8 n% O4 a; D0 ` window.location=url;+ v3 X0 \: I7 h* U
}# I) m2 f9 e6 \: x; L9 q- ?
# U( M* _9 w& d# l1 Z0 q4 I! j$ t
}
: K* R9 l' ] a* }% L //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认0 Q" C1 `/ u/ N: [6 s# l" L: Q
if(navigator.platform.indexOf('iPad') != -1) T" X6 Y. o: @8 `4 ?+ ^2 z$ `
{
6 _; j6 O( }6 J0 M2 Y* ? window.location=url;. r) f' T$ q- T& _6 n: P
}" G2 N& {% y3 s9 d, L$ j
//做这一部分是因为Android手机的内核也是Linux
0 Z' f7 K$ b8 j* e8 T% T: Y //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断! o" U0 `, \. _2 k. c8 q
var check = navigator.appVersion;3 ?/ E( n" U) [, v: P; _2 e( B
if( check.match(/linux/i) ): c9 E* Q) R; y7 g9 X$ n3 @# e
{& x2 v' }- E6 @6 _9 ^% S3 g
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
2 F% Z2 i0 u4 A0 R if(check.match(/mobile/i) || check.match(/X11/i))4 [4 K+ ?1 v4 A) B5 L
{: f' T1 L6 _& N- n) C. q. t
window.location=url;
6 R( a9 b5 o& f" B& ?, p }
2 S% s/ ]0 ~7 [2 i }/ b2 Y* I2 s" d7 U$ }2 [
//类in_array函数( x3 R! \$ {# D* V9 ]8 c
Array.prototype.in_array = function(e)2 `$ q- m; D/ r
{+ C( T# Q' ?. c2 X- o$ r2 O
for(i=0;i<this.length;i++)! E/ d9 U3 O( N( P. |+ H
{. X# v+ u; O; k
if(this[i] == e)
# w) d# l1 M5 H: ` return true;6 I6 R6 J$ C3 g0 L6 n, U; U
}
! f3 d: Q2 w$ ~6 M' n return false;
! E* J. n) {) H; Z }( D( m- _! d; U. n8 a9 ?9 k
}
2 Q: N9 s) Q/ U; Y% h. U mobile_device_detect("http://m.xxx.com");0 Z$ M% P5 @ | ^# g, _" x
</SCRIPT> |
|