|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
# H- L6 V# Q6 B5 Z' E
B C& I1 H1 o% W4 {. e1 e<SCRIPT LANGUAGE="JavaScript">
" U1 G: x# M5 ^1 { function mobile_device_detect(url)9 x6 j0 W1 y- W/ s$ Q* V& N# `
{& ~" V H }* V+ B
var thisOS=navigator.platform;4 F) l& i/ v1 {$ t% 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");5 Q/ A# ~5 t" O5 f6 {- ~! V4 b
for(var i=0;i<os.length;i++)
) b4 r" H: n9 n9 a- e6 e! Y {
. h2 D8 c& f% w1 m. [4 g2 ? if(thisOS.match(os[i]))8 |" S7 G9 R# n1 b, j& `5 w
{ 3 D9 X( n; v6 K
window.location=url;
8 u4 C) w, d* [$ A }
( r6 I; }4 k. { 4 |+ o0 Z6 N3 z$ `, s. A5 x
}" n6 r7 u# e8 E: D. ]% G
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认4 z7 [9 H& d, T9 P& o* b6 ?
if(navigator.platform.indexOf('iPad') != -1)% Z2 J; I+ |, M
{
) H# Q+ n- z6 D! R. Y3 e window.location=url;
+ \, ]$ q! g) c# j5 @+ O! \( H9 h; d }0 V9 b" q5 w9 O
//做这一部分是因为Android手机的内核也是Linux
1 B3 m$ E; k: M2 b& E+ B8 y' l //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断& V) x2 X# D5 w5 b3 C# h
var check = navigator.appVersion;
3 _7 `+ X) h! x% C) y if( check.match(/linux/i) )
1 c3 p6 n! s' u, s: B+ h {3 A) k. E5 |2 C% m& I
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
6 r6 y1 }, ]2 G! [$ | if(check.match(/mobile/i) || check.match(/X11/i))
: \1 l6 |* \' x- J5 {8 ~ {; Q( F9 z" D7 n7 }
window.location=url;/ E" b& S' n& {6 w( D8 _, G/ y& c& N5 r
} ' ]' ^. k" Q( `, x7 T& z* P2 m
}" ?0 L4 R2 [7 u$ m |; t( ]
//类in_array函数! g0 k$ C& I: e" j/ a6 B) B
Array.prototype.in_array = function(e)) |5 {; }1 s1 `6 H* b" ]! A
{& C( s# T9 D; ~% I
for(i=0;i<this.length;i++)4 o/ d$ p# }/ t/ p9 r& D
{# J! I9 W! u4 L
if(this[i] == e)
* W: Y" ~, G5 U }$ K# ` return true;
: V7 w- U8 E, K }1 f* ^) @$ J/ Z$ P5 F* m
return false;8 g; h3 T a, i. n
}
& K- y( B* i0 a0 E } ( _- B, o9 D; Y5 L- r) W: ?
mobile_device_detect("http://m.xxx.com");
& {/ Y9 g7 i+ b, N& M </SCRIPT> |
|