|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。' v# j0 H) N8 `& q; J% `
6 W6 K/ m# x! p<SCRIPT LANGUAGE="JavaScript">
! R& g& I$ [& m0 E function mobile_device_detect(url)
& K7 d4 c! i) k) C+ s! ` {; ^/ z6 y( l. c
var thisOS=navigator.platform;8 x: e/ s$ x% s/ s( k0 o3 ~2 }
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
( @$ q) a/ E7 A: | for(var i=0;i<os.length;i++)
4 B, ?* a \' _+ H {
% {7 |' i9 Q8 t2 r: b if(thisOS.match(os[i]))% e3 Y8 \: }, L: O5 B
{
& u7 J: X; @1 Q1 i" b window.location=url;
" c( H' I; t3 @ }
) E8 M6 `. m4 ?* L! R
3 w: s& }$ C# ^$ g8 p }! f1 M7 i8 W T
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认% o: ^- `' P' z) p6 R' ]+ U7 z' H
if(navigator.platform.indexOf('iPad') != -1)
) \- F9 a) `( V1 b/ \ {
; S& O- y/ \# S! d4 | window.location=url;
# F% t- }$ ?: D, G' a4 k. d }
( u1 |$ N# ^$ [ //做这一部分是因为Android手机的内核也是Linux- Q6 f' z" [6 R J' y/ Q
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
- X9 s W7 ^% G9 H. ^1 y5 V! V8 c var check = navigator.appVersion;! K# K! d! @. O" _% ~; a; x
if( check.match(/linux/i) )
8 h2 V* S$ x$ G- Q {8 @6 A$ m0 `8 G- `. }
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
$ ?/ A! m2 V) z7 ?% i if(check.match(/mobile/i) || check.match(/X11/i))- j. @# b6 s- w3 [! |! Z0 h \
{' \1 L B( m4 o) K7 w- ^
window.location=url;
4 Z' o; _( T! c }
4 i- ]6 y% s& N9 c9 | ~ }
# l# n; _/ N6 e8 U$ M/ I //类in_array函数7 i# H# K) u# o) o5 E l
Array.prototype.in_array = function(e)
/ D) `8 Z/ \4 }3 e {9 w: I1 e& U# R8 k4 n
for(i=0;i<this.length;i++)
: P* k9 K# `5 ^4 C9 ^+ W) b* y) H {
7 ~# D/ E4 h6 R" N7 r/ ^ if(this[i] == e)+ ?+ n4 i) I: m/ t, o/ a( e/ W+ I6 P
return true;7 ~) r& e9 C8 p1 a5 O# l: j
}
/ ?7 i$ o, X4 _; S/ I2 I y return false;
( U, q* {. ?1 B6 Z0 l B$ L0 h }* q: ~/ F- G, `
}
6 I3 D8 w& |- K( p1 Q mobile_device_detect("http://m.xxx.com");
+ K5 T/ C% l- p+ Q7 T) H* F6 f3 n4 ~( @ </SCRIPT> |
|