|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。& h5 S1 I4 v$ m/ H) l
7 C, {: W. O, q4 z$ b( \8 `* J3 h* `<SCRIPT LANGUAGE="JavaScript">, {) ? L2 v! ]' @: Q
function mobile_device_detect(url)
6 z+ n9 c0 p; P* j {3 I# `& _# J8 v% N# z' r
var thisOS=navigator.platform;2 G; G( [$ Z$ a, S/ A, X, Z- N) w
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 j- x/ s" D0 S- L* R Q
for(var i=0;i<os.length;i++)
! u! Q2 v- R9 _+ ` n2 c, q$ P {
8 l* z7 b( g3 p7 p8 X if(thisOS.match(os[i]))) ?6 F1 l* Z( D/ ^" E
{ ( Y& O4 B' D, e. N3 \! u0 A
window.location=url;
* e* X% m: v' B& C! S7 y8 ^ }
( x7 K# W' c' @- p / w4 U/ L. `1 N- `
}% U6 _6 a W8 X3 m2 [& H) a
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
) ?$ e' j: L( ^" H; N$ g7 S1 d. _ if(navigator.platform.indexOf('iPad') != -1)
. v0 v( i2 A# S* {- N {
! k: k- v, R% l; F# b window.location=url;) S) e. E5 U" _' y
}6 E" Q$ u. L& }
//做这一部分是因为Android手机的内核也是Linux
5 ^7 j; R2 |% K5 c8 ]- @ //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断4 s9 M+ P% U- g6 W9 u
var check = navigator.appVersion;( O+ f: P0 i7 A$ \% m
if( check.match(/linux/i) )
( |% D7 r0 l( T! ?) N6 g) I6 S {, y4 s/ C2 S% O: d
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
* }) F& L3 z1 X! v) [$ Y if(check.match(/mobile/i) || check.match(/X11/i))
, Y9 M! G, V; l- m5 b" A { ? }- t5 A. Z3 b
window.location=url;
, N1 N# P* v& k5 M4 V. i } : k5 t1 X; U) T3 Y, O3 B
}
, V* T7 @0 {. \3 e6 W6 K- A //类in_array函数/ h- J# X0 ~2 q( @% E; R% u1 R: P7 ~: o
Array.prototype.in_array = function(e)( c% s. |8 s$ q* s! F$ f* a0 A
{6 @. {) Y6 j4 g' N9 k5 m
for(i=0;i<this.length;i++)7 V# D9 U( d. b
{5 R4 j9 v& L0 ^- h: k4 Q+ |8 R8 E
if(this[i] == e)
: a3 j9 N. l& ~* l return true;
4 i5 p; z: n3 s5 _ }+ k+ g" i) \; i2 m7 o
return false;% w% a1 Z' U5 f2 @1 B9 [$ F
}
/ N+ R) V+ u: Y0 I0 d }
. H' U: o$ d J" O9 s4 B3 g mobile_device_detect("http://m.xxx.com");6 ?- w7 x: m+ B8 f. R
</SCRIPT> |
|