|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。0 h& e' i9 z. |+ X1 D4 A
/ W2 {6 ^$ C' s: u$ s! t: f- ]<SCRIPT LANGUAGE="JavaScript">
& p7 o ^+ z( E: F) Y/ \ function mobile_device_detect(url)
% U" S: u' P( `" H7 ` {6 f& X6 B, n Z
var thisOS=navigator.platform;
; g6 P+ i& E, ?; S2 ` 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& L7 R% t% B! y
for(var i=0;i<os.length;i++)" E) O% @% m9 G/ {
{
% q. k; w; I" \' F if(thisOS.match(os[i]))( q& k P( ?/ Z9 k2 H$ u
{
' U2 n+ `$ b' Z window.location=url;- e9 h" j0 h& M7 n4 C2 J
}
3 ^5 |: O3 r* u8 r4 }9 s ! d5 Y+ L- l/ T, U: H2 G5 }$ D
}
6 R: L7 ?' U! l+ g5 t- Q //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认- o9 l# a8 p2 b) S4 H- A7 l
if(navigator.platform.indexOf('iPad') != -1)! y# K, W$ b, a% L7 k& S7 y
{! `4 z2 H+ |8 A& H. {* `* m
window.location=url;0 S: D2 V2 f0 e* Q9 X7 G
}) S- j1 `5 l& g/ q+ c# v
//做这一部分是因为Android手机的内核也是Linux) c ^' T7 N4 s: }4 z) l5 J- j
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
0 n e) z' B6 J5 O; Z3 \ var check = navigator.appVersion;
+ D+ f6 L. }# k5 G if( check.match(/linux/i) )
6 X* ]# p1 _7 d8 M8 F3 x {
5 L0 r& z; ~, _; ^/ V( c- j9 J //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件' ^/ i6 i. |6 @% J- U S* O
if(check.match(/mobile/i) || check.match(/X11/i))
$ ~( Y) {% Y/ O9 d5 f {2 q/ s, J1 y+ L7 d: ^
window.location=url;
+ t. I( ]" I2 N }
, m. P; n0 i2 l. ?4 R }7 \, U E9 [" } {; R
//类in_array函数
# K* s( `9 |( }7 e! G9 C5 \, g0 t Array.prototype.in_array = function(e)0 K8 N, P- \! ^9 A: ]
{2 Q- Q+ @4 L% I8 f5 O2 j
for(i=0;i<this.length;i++)* X( ], O( u; L0 y# d- x
{1 x# l1 p6 w, ]" S: q) F
if(this[i] == e)4 u) z- |# {6 s; z$ ^+ U. R
return true;, R3 G" M$ U# u3 W8 ~: ^: B. i
}; X! P2 \/ ]7 l. @! p2 t3 [
return false;
1 m( X4 m/ T2 Y0 I }5 J6 \$ D, h4 ^- }" e1 |
}
" x8 b7 ^/ B3 m% |. w mobile_device_detect("http://m.xxx.com");
$ k! N2 y- }1 {; M7 O) m' y: W% a </SCRIPT> |
|