|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。# L5 y* c. p' u( I) ~+ s2 {
$ t6 `% M4 j# V" f* l<SCRIPT LANGUAGE="JavaScript">
6 P# E( I: B) S function mobile_device_detect(url)9 d1 e& ~8 B4 y" q. ]
{: B" o" X3 N; A6 q: }
var thisOS=navigator.platform;# A% Q2 a" G8 F) 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");. N& A0 a* N9 ?8 X' g# Y/ z9 T8 q2 S
for(var i=0;i<os.length;i++)
( q: ?6 G, W, K, V+ Z {( t3 q& a* ]+ L, {: E: F4 j7 G
if(thisOS.match(os[i]))
0 h2 l0 D! _) ^' e3 @! O- Y& Y+ ^; T { . ]1 _. S2 r7 L' o, e
window.location=url;
2 Y& Z& }2 n3 g, k: e5 x, B; J6 s }
0 I7 w$ A5 g6 U1 R * `; k+ r1 e3 w; w: E& {" l
}) U% {/ @- N1 T# F
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认& ^: t! I5 G0 f7 m" ~
if(navigator.platform.indexOf('iPad') != -1)& x7 y. t7 r i' W
{
0 z& A+ Q1 S" u/ k, b) x! P window.location=url;
! V9 o3 h o Y, h1 J k( X }
/ i. N" W5 n5 V& I/ ~, x! m //做这一部分是因为Android手机的内核也是Linux! v: ?' ?0 H% h3 x/ K0 X
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
' y ?" l5 g0 Q/ M1 C var check = navigator.appVersion;
5 d! F2 N& t! S: s: q) x0 A if( check.match(/linux/i) )6 s1 _! e( u- F. V/ Q0 i
{
# J) H: m2 c: D5 g8 v //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
% n x. ?8 g1 s; H$ q/ u0 P if(check.match(/mobile/i) || check.match(/X11/i))
T' @& O" b! @% K; G& l! C1 |2 H {1 P: Q+ [* Q# }* A
window.location=url;# i* d3 E& z- T9 O
} 3 ?7 D4 A8 H- }8 P; x
}" y" g+ x2 S; K% `3 L- J* M5 F
//类in_array函数
4 N i k3 t4 K1 v; c C1 f) x' q Array.prototype.in_array = function(e) `$ i1 i1 K; t$ h9 a1 |: K
{
- A/ _6 b- U% p% E) O- w* s0 P for(i=0;i<this.length;i++) V/ {/ ]9 d2 ~, z8 x1 M
{
: R" M5 X. }% i, N! o. g W2 P if(this[i] == e)
% D- W; Q5 H; h# e. j3 b+ A; J return true;. ~2 o) _6 c6 L; z1 z5 G, p
}
* r7 @: r7 l- d' T6 w return false;) B8 l: o# D( J R+ O+ c T- N# K4 ~
}
6 L. i/ L$ a- D8 i5 F) u- p" s } 1 g, d, O- C! h5 e9 E
mobile_device_detect("http://m.xxx.com");
0 s. K$ Z$ [6 _& D0 \ </SCRIPT> |
|