|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
- g6 i) ^( d0 I( h- J/ g) ?! t8 J2 B2 i) R
<SCRIPT LANGUAGE="JavaScript">7 D4 u# m, B' X' |" i0 T
function mobile_device_detect(url)( D3 N: r4 W4 k0 {; L& ~' ?- V
{
7 u& O0 g: R# l3 u ` var thisOS=navigator.platform; Q0 v0 t5 f0 _! m
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");: i' ^( I( X" e) g& _ ]( K: u
for(var i=0;i<os.length;i++)
) J! B, e' B, {8 M; A9 b2 d7 O- r {% Y" O- m$ u/ n: i
if(thisOS.match(os[i]))0 i2 d6 n# r# A9 |
{ 5 X2 \5 x6 p% b' V
window.location=url;! Y& y) Z7 e/ Z1 m0 R4 S! I* y
} F! ?# k* f5 U5 J# `/ Q. Z5 k
/ x! l/ y! G2 N! L9 L+ F
}
! V7 C) r% g: w6 i //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认7 ^4 @: g' C, U }: C+ {
if(navigator.platform.indexOf('iPad') != -1)) v/ H$ t% R3 T i' C
{
! `1 ?6 _% {. I6 V8 Z5 E9 ]% J window.location=url;& X' i) K9 c& N1 D% r7 C
}
' Y% }8 a" r" c //做这一部分是因为Android手机的内核也是Linux
, s' M1 P: |$ t c //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
; p/ J: Y5 r. w' B var check = navigator.appVersion;5 ]# O3 o* K; ]& `1 Z
if( check.match(/linux/i) )$ v7 Z5 f, p; K1 }" y! i
{
+ K3 c( E* }5 T //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件4 z$ L# f9 }9 d# y2 [% ^
if(check.match(/mobile/i) || check.match(/X11/i))# ?, x3 X7 h; j) B/ S+ l6 _8 d2 w
{
$ f7 r+ s: y/ Z3 ~+ W4 I" s) A window.location=url;
% ~' m5 p7 L; N1 x }
5 \, l& s6 M F: P( E# y" A$ | }- U" L$ `* |* D' ^5 x" I1 `) G
//类in_array函数$ z$ @. g5 u9 u1 z5 y
Array.prototype.in_array = function(e)
+ V ?3 ?' D. a* Q {
, Q9 i! G% F/ g. u+ J; g d for(i=0;i<this.length;i++)
/ h( V' \5 S% I9 V {% L% S, t+ v7 I2 d- z* p* k
if(this[i] == e)
8 W/ S3 @* w/ V, \' z7 P6 U0 q return true;
+ _; _2 I W4 X }
0 j. h+ `3 x8 v9 [# |. { return false;
' {% F- t! L1 }% Z }* s9 \4 x V- L m- ]/ p
}
3 g- ?9 J4 ]" o$ ^% |" X8 @& L$ l mobile_device_detect("http://m.xxx.com");, p' a* m8 W; }9 J" e+ p8 x
</SCRIPT> |
|