|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
6 ]7 c; q6 u* v( B7 n: w) [2 _: X P! c) j
<SCRIPT LANGUAGE="JavaScript">
# k6 b9 e- G1 e5 A- l function mobile_device_detect(url)
- @' I6 y* g. V' w6 F5 v {, J V9 H# n' m; K9 G5 I3 I A; o
var thisOS=navigator.platform;
f7 B" f6 d" v0 r; Z7 e, V2 X var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
- D: d2 H1 ~/ S4 v/ m for(var i=0;i<os.length;i++)
, d2 s7 M$ c- V. E+ [. r {
7 N7 {& B& @, ^* r5 e1 R if(thisOS.match(os[i])): j: X/ _" b/ B4 d9 ^+ Q) u
{ 5 Z2 i) z7 a+ {0 Q
window.location=url;9 e& h4 n. c. V
}
3 a7 U$ W# D; i' P+ y0 c! w 2 ?: {/ I" ?2 y
}# L6 Y3 N2 C$ a3 ?
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
# Q, N1 ` U% w0 v; Q if(navigator.platform.indexOf('iPad') != -1)- | Q# T& P$ r K% e* n
{
, e q' m1 F+ f9 o0 f window.location=url;3 L% c( r' g$ o1 |" l9 l8 R
}
1 o4 f' ^# |2 @4 G //做这一部分是因为Android手机的内核也是Linux
( C7 }% \, B x2 c7 r5 z) A //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断0 m3 b' `- g) b; }0 t8 R
var check = navigator.appVersion;
9 r; ]' J6 ?& p1 Q9 D. P if( check.match(/linux/i) )/ }% y3 X9 r9 o) g
{; g5 d* R3 `9 d8 i" G5 ?
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件1 N9 l6 ]; D$ e3 j \
if(check.match(/mobile/i) || check.match(/X11/i))1 R9 O8 O, v/ P. P
{+ O* B4 d$ ^4 M: b
window.location=url;
v- Q8 j l! e `5 K2 x" _ } ; l& M# [5 u8 q. S
}3 E5 z2 V* `& y
//类in_array函数
# m2 W( ]. u% f9 z: P Array.prototype.in_array = function(e)# z. M$ U' |" Z
{
, t e" d6 k, c7 Z0 Z' @2 _ for(i=0;i<this.length;i++)
5 v ]- K) W$ p# L$ J/ l4 }" B {
5 O+ l3 T0 a$ {' P% g if(this[i] == e)& p0 h4 A6 X) N
return true;1 V- H; S* J; \! `/ j' q
}1 B4 R5 s# }9 b, ^0 f6 a- w3 M5 L
return false;) P+ q! r6 J% a
}, r; a/ u5 B( {. J" J0 `( A& o
}
/ {4 g6 R1 y; O- R mobile_device_detect("http://m.xxx.com");
4 _8 x& H$ d: b7 e </SCRIPT> |
|