|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。2 n" G& m$ m, h6 ^
- \; d, M5 e% U* f% j
<SCRIPT LANGUAGE="JavaScript">
; S O7 q/ G9 U8 }: i$ L5 r function mobile_device_detect(url)" Z# U! O7 a6 Z2 J0 D
{
- Z0 p2 y2 S- E# W; f var thisOS=navigator.platform;
0 v+ I6 |8 [$ P- B( } var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
2 m% T U" x W( ^( i1 l, f; M# s1 [ for(var i=0;i<os.length;i++)% l! J9 H% B+ V
{
6 ~6 H2 G, U/ z" S8 o5 S if(thisOS.match(os[i]))
( Y8 l* E% |% E6 i1 a" Y" _, @ { 3 V9 T( k( n, D) R
window.location=url;. q' H- Y# Z$ m$ A6 E' R
}
$ l5 s* \& L' f+ T% f & f/ ~* r; j# U! G" I
}
7 Y4 w% `4 \/ [) | //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认8 s! Y# A2 g1 a8 O4 k( k7 z8 U5 b
if(navigator.platform.indexOf('iPad') != -1), ]- j) @7 m9 O& J! O
{0 X! a$ w. K/ a+ f2 S+ t* v5 y" O
window.location=url;1 g6 Z3 ^$ l+ Z% K4 H5 x x
}! V; ]: ?( v+ p( v+ U
//做这一部分是因为Android手机的内核也是Linux' F U1 N% g) O
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断' @: w$ ~/ V* g% Y4 v
var check = navigator.appVersion;
' h& V6 A* {. E5 ^& `8 y if( check.match(/linux/i) )7 y2 A* q" _8 o2 d9 h# s6 e8 d; k
{5 _. t5 n- D) c% u! M* Y t0 ^2 p0 {
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件. w5 L; x# |$ s3 N* M
if(check.match(/mobile/i) || check.match(/X11/i))
# P2 ~& ^2 B2 ?: {! p1 ]+ p {7 Q4 J8 u- X: D4 \; h
window.location=url;
* A, ^0 W. {1 [3 p/ B } ; _, X: Z/ O/ N- o
}
6 V+ `* q: z* ?# ]' U- @0 b/ v1 O //类in_array函数
+ F' g9 `8 _9 N- ] Array.prototype.in_array = function(e): Q0 I5 P& s# N% D6 n5 Z$ E
{
! M1 g* i$ W! | for(i=0;i<this.length;i++)
]+ M G. U! n. k" a {) J# Z. A% [- Q' {( D$ c
if(this[i] == e)( {$ N3 Z# O# ?# h% u- O
return true;
7 V7 G, q4 G; _; f3 P# e }' f7 m# ?% e" N
return false;, s/ X1 D3 K) S8 q/ f) g6 D5 y+ f
}# z2 I) c! v1 V- e
}
7 [1 O T( q; z/ d: y mobile_device_detect("http://m.xxx.com");6 G; Z$ o" C9 i# I
</SCRIPT> |
|