|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。$ H$ b3 y- H! h' u' ^4 B7 N
& N5 J2 S6 B* Y+ j8 a& d<SCRIPT LANGUAGE="JavaScript">+ \: m7 y2 W/ o8 Y) n
function mobile_device_detect(url)
- p+ u( w+ q$ _9 X {
$ P0 d, X/ r" `5 I3 F/ F var thisOS=navigator.platform;
* M5 Y& a, i7 e3 b0 T var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
3 ~- i6 V' t7 s9 L. p/ J. R9 f for(var i=0;i<os.length;i++)
% e* S; A& C# d+ X' Z {
9 {: W5 U( l0 h- l% c& B if(thisOS.match(os[i]))( O! s$ _' o# g5 P! }4 [
{ 0 p" l6 i, g0 X, D- }: b8 ]; x
window.location=url;
0 D. s5 v9 c8 C0 t0 ` }8 B1 f. {$ B" l' S
& x* E: y& S" h: r }
: U; A# @/ r8 G* l- e //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认" V" {/ P% U7 ]
if(navigator.platform.indexOf('iPad') != -1)
) E/ _( H4 ? a, o- O' i, D {( H+ n/ }: V" h+ m
window.location=url;
& J# a+ N% y; |! |. s4 E, E8 H5 x }
( k. N7 w& j; ]3 G% ]' O //做这一部分是因为Android手机的内核也是Linux
, J6 P% |2 W7 E' x" N //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断 [+ C0 o: G' z2 F3 I2 H0 }/ p
var check = navigator.appVersion;& Q; |& v2 b1 j' U$ Y
if( check.match(/linux/i) )
+ u1 c$ P% J9 g& I: w {9 b7 }, Q+ N, j) G. a' }5 h& Z
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
) z y- N* A. _# J l8 b4 H if(check.match(/mobile/i) || check.match(/X11/i))* k5 r3 n# d3 ?, g- p+ d* b
{0 \$ A8 j. I! F) C0 S
window.location=url;
: F& C c0 l3 v } 8 b* T4 `3 h, s: t# P# \4 }/ t
}' I3 y" K1 b2 `1 Q" F
//类in_array函数" L) O; P6 M. m$ W' v# k
Array.prototype.in_array = function(e)1 l9 L8 y7 A2 y9 u
{
% p2 D% i( W# i C' C for(i=0;i<this.length;i++)
) \- v7 }2 r' k( i" K) B; n$ `8 V {
h* C! Z: u5 `: t C if(this[i] == e)
% O0 e: A# U; F" u% ~) q( E return true;
1 s& [; f3 Q; m0 Y# u: @ }( Q7 ]3 Y$ ^3 ^( P" g: l* m
return false;
; {6 E H0 ^- O9 A1 v# R }5 |8 ?$ A, D! \. H
}
) X' K- a5 S9 N& Z! w; A mobile_device_detect("http://m.xxx.com");
' ]8 H1 M" i, D* l </SCRIPT> |
|