|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。4 }2 J; L9 \9 ^! l k+ ?
0 Y' h& S4 k z<SCRIPT LANGUAGE="JavaScript">
. v. D% r% G9 J8 J# o, R4 A function mobile_device_detect(url)
( [' x) \" i, {7 }( F" m {
$ e R2 [4 ]8 ? var thisOS=navigator.platform; C- e3 l/ j9 j0 m3 ?
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");9 k/ f+ O& T* C- L8 S, X- A
for(var i=0;i<os.length;i++)
; J! [9 V2 G$ Z# s" ?' E4 { {
0 m, i; ~2 M# c, v1 k$ x# O if(thisOS.match(os[i]))* c! B1 d% B- g, D( j" k
{ ; h# X% _" |* A d P4 u
window.location=url;4 _" c5 U: o' v# Q* u' n% s# @
}
# u. T; n0 v2 }$ e. Y9 G 5 W% f1 D8 w- O. Z3 u
}
) W; i) c1 t, M0 R; G5 }% K //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
3 j. V8 ~: r0 S: p9 f V$ D' N# C if(navigator.platform.indexOf('iPad') != -1)! Q+ t* x, A' t; Q
{: u f" `' i! v1 V& j A2 [
window.location=url;% K4 Q& |, G' ]8 @* i' h
}
) x8 C8 j) c2 L& Y //做这一部分是因为Android手机的内核也是Linux
9 D& r- `( P" ]/ P //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
/ c+ \6 [8 u! C! Q4 o var check = navigator.appVersion;
. L# K; y- N4 M- `1 L, [' q& @ if( check.match(/linux/i) )! d- {% a G) S* e: n. V
{8 j! `) q R+ g9 s1 W# ~5 Q
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件3 w5 x4 ~6 m) h9 g3 B9 I
if(check.match(/mobile/i) || check.match(/X11/i))" X8 ^: L) e# r( s2 P/ |
{
% p2 v. p, t4 ]% `) L% T window.location=url;9 }3 e- S: T# |! {6 n+ ~
}
2 Z5 G1 w7 E8 A0 k }
4 F8 K- r6 f' L1 e0 b: I; ] //类in_array函数" Y1 y- o- `8 d2 U8 a* g
Array.prototype.in_array = function(e)7 U o( A, d g
{
4 C" e# S1 o3 Y P. x& v ] for(i=0;i<this.length;i++)
- L0 |8 z3 H2 \+ Y {* m, s# I, q6 U: q: \/ }: x9 d5 c
if(this[i] == e)
, d- B% s, O* g5 ~+ z' B8 N+ N. s return true;
% v" s* ]- A, y0 m }
$ |2 [6 J7 ]1 ]! K. v return false;
: D* u7 R! V( \4 V( B4 V# w }+ F- E( j" M5 X+ p% w7 h& Y
}
# x8 @% `, K8 q mobile_device_detect("http://m.xxx.com");7 c4 C( t* Q$ i
</SCRIPT> |
|