|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。9 H! F' M, Z# l T. H, }' W
" x- K; ^' ]6 y1 z+ q7 d5 y; y3 o
<SCRIPT LANGUAGE="JavaScript">
* E5 \; n+ o% W5 C" V function mobile_device_detect(url)
1 i7 r+ C2 T( y; y% F. J {
/ Q9 x, c3 |/ p5 c% h var thisOS=navigator.platform;
- D5 n3 l. R; M! `& O; H var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");4 j, n+ Z0 k# T: l
for(var i=0;i<os.length;i++)# ]9 I! H6 K9 d3 L9 I
{
7 |/ T2 c. G! }$ M5 B% s/ Z, ]! i if(thisOS.match(os[i]))
9 a% o7 e' u% w% d( x7 ?* ` { * }! Q, F8 p& m8 g* b9 p( P
window.location=url;
0 Z8 o3 q$ ?1 ?/ | g- ~; @ }( h) J( s5 {! B# I8 }* v& v/ `
5 J! i: ]3 ]8 ~5 |1 g }
5 U' A# [" d2 q/ ^7 J* o2 [ //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认' X9 d' G" u% l+ {
if(navigator.platform.indexOf('iPad') != -1)6 m2 `* a2 P% t% {8 j( ]5 @) n
{9 C+ s" y3 @& l' Y4 l C) ~3 z ?( I
window.location=url;. d0 \% }, |8 `. t# B, {
}
4 N- {- ]" z. c& e0 R" l1 q, m //做这一部分是因为Android手机的内核也是Linux
6 | ?( Y8 ]) w5 c6 k" J' b; d //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
6 u, ~/ f5 G0 J% D4 D3 T0 l- H5 @ var check = navigator.appVersion;
* w% B; d% ~* C c5 a if( check.match(/linux/i) )% b* q) e2 m3 t0 G
{
1 f/ Q% i! u: m" y: w/ W //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件, q8 k6 E- A0 a, l4 x8 o/ a
if(check.match(/mobile/i) || check.match(/X11/i))8 a" N' l) V5 i) |* ^! M+ L
{8 i/ E. z/ J! Y
window.location=url;" [9 N9 W. X% e0 g/ t3 |
}
[; h1 n$ Z7 U& F5 |$ n }9 y+ u: u+ P5 f7 I
//类in_array函数( B! u7 O m4 b9 ^( @; i
Array.prototype.in_array = function(e)
B9 c1 v/ k2 x0 D- V {6 [6 g+ Y/ H" ~* _9 v, V
for(i=0;i<this.length;i++): n5 E3 W+ M2 x! c/ x% a8 F; l9 A
{- |) i9 T1 o5 i) V, h
if(this[i] == e)
. p1 \5 H/ V, O* C return true;4 k$ L P8 {, @5 E4 r1 s! l# A4 {; N
}2 ?2 _1 v0 ]1 M @& M& l9 ?( G" g
return false;
& C) Z& ^* i! E; \ }
* ^0 ~% C( w% R } $ i$ [$ J; O3 P8 v3 V( m! M& A/ ?9 B
mobile_device_detect("http://m.xxx.com");# ]: {! Z$ m2 ~9 N' o$ t
</SCRIPT> |
|