|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。& O. s* O/ F' @% B+ ^* I
" S2 a8 t7 `: g. B& V+ f6 ~# q9 `
<SCRIPT LANGUAGE="JavaScript">
8 l: S. _( J9 F function mobile_device_detect(url)
" }, E! |7 _& j9 O" \; S- f {& H1 Z5 k* z8 _- ~) l$ z! {
var thisOS=navigator.platform;
1 U/ s7 W! ^4 x0 v/ B) P6 o var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
% H9 t% @8 m9 |0 A+ w& i5 ? for(var i=0;i<os.length;i++)
" ]/ {1 g$ R( s; ^8 |- X {1 K, o. J7 U& @
if(thisOS.match(os[i]))
5 B1 @' d: b n" b; N { - L, A7 K: Z+ v' n5 P0 } t& n- a
window.location=url;# b! `! L1 f3 ?% w
}
* e& n _$ w7 L" T* X
2 W! c. a1 e+ R }
* q- [8 d: G" B: \" X //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
` ]% k9 w# {3 h1 s7 N, X% V; ? if(navigator.platform.indexOf('iPad') != -1)8 r, r+ q# T8 g% e0 N l" W
{2 [- y2 M5 F5 z B' d7 `
window.location=url;
4 l8 {6 C* ]" R: M( P7 e7 ?6 S }
' N& l3 ~( y5 \. Z! t) N //做这一部分是因为Android手机的内核也是Linux
4 g. c. ^# j4 x //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断, v8 Y# b0 u+ v) Q9 l
var check = navigator.appVersion;
' `# q1 M. C% b( E. A6 w8 K4 D) m if( check.match(/linux/i) )3 u9 R: f) W- P) \; Q
{
# g# {9 v5 s2 o$ {0 Z //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件2 V, w+ U s& ^+ |' h9 r
if(check.match(/mobile/i) || check.match(/X11/i))* g% B( `" A# F- L. s
{
6 h3 u+ q% |7 L5 ?* {' o4 c' y window.location=url;
* W+ u" N) b9 b } . o1 t: R6 V' o* W
}7 m/ A! L7 r& m5 ?) O! e
//类in_array函数, m2 p0 h, n: D; i
Array.prototype.in_array = function(e)1 a* s V& r4 c, u# x! a5 [
{9 M& }. M2 H: I- B* E
for(i=0;i<this.length;i++)
7 B8 \- A/ r/ Q. c8 l; F. a {
8 a6 Y5 W2 }6 E! L5 t% r if(this[i] == e)0 q0 F/ U- M( e6 x' w; |6 ]
return true;. P* e% k$ T4 `0 M0 I$ S- ]6 K
}/ f. q$ C1 k! |9 i
return false;1 } l) D* ?; @# \* ]0 }% u
}
! s- T7 D! R* i& }8 G- Y }
, V% I5 f/ ~$ f mobile_device_detect("http://m.xxx.com");
/ C% d5 |2 Z- u2 b$ d </SCRIPT> |
|