|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
( @9 N+ y; I8 N) P9 y: V% @ |! h" M) u
2 T9 s; h, ]7 p5 `<SCRIPT LANGUAGE="JavaScript">
) W$ f* R D' Q l function mobile_device_detect(url)
3 j9 t( t8 F6 x1 _8 Y3 I" K {" o1 Q" `6 v1 }
var thisOS=navigator.platform;+ o# M' |; _: P& T r: k
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");! ~: d. Z3 S" n6 G. r/ A3 B
for(var i=0;i<os.length;i++)
! V9 G$ n6 N4 [ {
~7 R Z8 x1 `5 _ if(thisOS.match(os[i]))" x' B) S, A8 ~" _
{
( F* p0 a, V# X" v0 c q6 p window.location=url;4 e5 k6 K4 H! j0 G' m
}, R" q/ o7 L1 L: Q# R$ G7 X
g* k$ F" Z. |" ?# j' S }
+ s& z) n0 R9 k //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
2 \9 G f6 V S9 j S if(navigator.platform.indexOf('iPad') != -1)
( ?/ @& g4 p8 b m {
* g- i4 ^7 c3 T7 F& n7 b0 ?% ^( C window.location=url;- X+ Z3 h" d. g+ t( [: A! }
}
# d- P j8 c; ^" e* } //做这一部分是因为Android手机的内核也是Linux
+ z, ?9 y% n, \' l //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
b! k; k# I4 D0 B var check = navigator.appVersion;# s0 i1 Z- a# Q( M9 w' g
if( check.match(/linux/i) )
1 e, c5 E5 D" n8 \# D: v {
* p6 w& E/ m! F' `; d6 R, o //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
9 V" x- Q/ e/ h& p& a" ]. q if(check.match(/mobile/i) || check.match(/X11/i))$ n6 w4 [4 W( |: H. u
{
2 `# `9 T& y( i6 o9 \6 J0 _ window.location=url;
5 Q7 G( X* N6 N8 S) | } l } $ A6 o! o+ M* L' b& O% g6 ]
}
- s1 e, E# v0 n+ w! W4 v; i5 d //类in_array函数: I) b7 C* x8 D; i) V5 C2 c
Array.prototype.in_array = function(e)! X" a* [! H. i
{% t3 B5 G+ H6 n. p6 P: r
for(i=0;i<this.length;i++)
% A$ s; H* r. E0 v% e5 U$ I8 m; \" Y {
8 p e4 e0 f6 g- ]$ j+ ]6 {9 b if(this[i] == e)
5 U! U. j- |" G1 M$ R, o return true;
p' \" [6 l- f/ i% I7 v/ d }
4 v) m8 M& O+ X Z) P9 m return false;, W% {5 Y' \) Z6 I- [
}0 j6 K" j0 @! g- L- R" L) G
}
1 P: i6 G) M7 ?) u p mobile_device_detect("http://m.xxx.com");. P% e9 m. h9 p, Y) B
</SCRIPT> |
|