|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
5 @) `% z7 I8 M1 C' d
! `: I4 o% Y0 m- m<SCRIPT LANGUAGE="JavaScript"># j9 N5 ?( B9 U s3 Y) F( y6 L" V
function mobile_device_detect(url)' _% d+ F0 \0 f, }/ L! K8 `
{6 w2 V' A" L# o% d
var thisOS=navigator.platform;
" t: }6 \* h }' 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");
8 a( n+ m4 p3 ~+ n7 P( O2 b! t; I for(var i=0;i<os.length;i++)
0 t, @. t Y& ]6 x4 L; m {
4 N- q% C& ^: T$ o) f if(thisOS.match(os[i])); a7 b% k+ C+ g! `$ a
{
# S. H2 ]* j& G. A6 z window.location=url;
) R9 p3 H" ]5 b+ x$ ~ }
4 F7 L' ]7 [, p0 C1 G
+ a. e% K5 s3 U+ D5 o9 } }
( R& D, x8 r% {% M. x6 u //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认- w: \3 s) C1 W& c' z2 B/ d; [
if(navigator.platform.indexOf('iPad') != -1)
' l0 q# k- s# F {
/ d# H% M& h9 D window.location=url;
" K" k' h; {3 J M4 m; t }
( d; o+ Q+ ?; k1 x' L) Z$ \ //做这一部分是因为Android手机的内核也是Linux
- m& d- {2 |* F$ x* e //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
s1 H, q* p4 `) r1 o9 q* O var check = navigator.appVersion;
5 h. U. G+ |' k; Q9 T if( check.match(/linux/i) )
6 J1 Z. P) \* k2 ?1 } {
/ X7 n9 I7 L; m5 F //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
& ^7 X1 _2 O- O) s Z: ]% }% } if(check.match(/mobile/i) || check.match(/X11/i))1 n" P4 A' G# G: _0 x
{
8 F8 U" m3 c0 c) B# t1 c( W window.location=url;
& K2 M1 H$ S7 I, b1 ~ } 6 H/ s+ q, W/ h) Y# f2 p3 e
}
. Z% A) y4 Q( b0 w, v2 }! d //类in_array函数
) @3 y2 |! B, H$ k$ y Array.prototype.in_array = function(e); j, e0 ~8 { g$ y+ X
{0 Z, b. f; B; {5 n' y$ w4 Z
for(i=0;i<this.length;i++)
7 V2 X% A& |8 c* a! f6 i1 c- | {
, E, o2 ~! f8 g) E if(this[i] == e)
, {. T) q$ Q* s1 I) Q return true;
4 A; Z4 x" Z* Z& |. F- K }3 W2 Q; r6 H! b5 P, X0 Z
return false;9 g7 E' F) ~9 N9 Y$ F" N
}
) r* u7 p! \' N- E } 8 O( k# z; n, f5 ]- T" R! [
mobile_device_detect("http://m.xxx.com");
/ X0 ~2 D: Q/ C </SCRIPT> |
|