|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。% ~' m9 P! X$ k
" }8 K; o' ^4 w+ L$ \' D$ k) e
<SCRIPT LANGUAGE="JavaScript">3 g5 P. ]( e& r6 a. B7 [
function mobile_device_detect(url)
6 c. l5 I; b$ \5 r9 C' [# Y {! E6 z) _0 a* J/ i# v Q6 y) `
var thisOS=navigator.platform;$ W: x. D6 ~' N! o$ e, ]7 s3 q* n
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");) Z" |, \9 u j& d
for(var i=0;i<os.length;i++)' o8 F- f( C" Y H1 q q/ R3 o% G, H
{; k0 K, m0 Z* V% g' I
if(thisOS.match(os[i]))& L$ g% r+ H* q8 x! f3 z
{
( P, B6 N# E- M* @! o window.location=url;
0 A5 a! G5 Q" H c& a& l } b7 m$ J8 K$ H. b
; G5 I$ x* _% E( ]* D }
( b) k$ ^( A. z+ z8 j! l+ Y5 k //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认# L. L9 l! R, c( \/ ]
if(navigator.platform.indexOf('iPad') != -1)
( d4 c$ w2 G4 [" ` {
t3 F9 M$ U3 d# f. D. C% I7 ?& B window.location=url;
3 e& @7 c k* o V7 A3 m& e }
% O( M6 x7 n0 N; A% t6 [/ v# t3 q //做这一部分是因为Android手机的内核也是Linux* K6 Q/ j+ W) E) T4 ?
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断8 ?0 {. ` v$ |: g) d$ Q, f) @3 m
var check = navigator.appVersion;$ h0 J& ]' p F( b
if( check.match(/linux/i) )
2 N' {6 c; @/ g( n: y$ [ {( G$ ]+ A+ K7 V S
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件3 @1 d+ R* c- y- q" J
if(check.match(/mobile/i) || check.match(/X11/i))4 X& C+ t7 b9 A
{
; J7 x$ b- }# A3 D y) D window.location=url;
7 P7 Y2 s1 q% S% z; } }
$ T [ G; U7 Q$ G5 } }/ ~: Z% m: s; X0 R X: ^6 }
//类in_array函数" }1 r) q" I b" b7 o5 c
Array.prototype.in_array = function(e); k+ Q+ }* @) K/ S2 U7 h# [
{+ w; q' c1 a; e. ? o% |! h8 b
for(i=0;i<this.length;i++) k2 ]! y% B! j3 B
{
: Z- {# W' `( j" N+ V p ?6 V if(this[i] == e)
1 Q$ `# U. R" k1 @( F return true; ?, [/ d2 U) G9 v1 O2 \! z: ?# ^
}6 z( o2 k, x9 P8 F( ~: [
return false;
6 J; O$ L4 e: r7 N3 s) z }
) A& t* u* o; g }
8 v/ m/ p, `3 Y2 e* p& I$ z3 C: G mobile_device_detect("http://m.xxx.com");6 m& D- n0 o) J
</SCRIPT> |
|