|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。, x1 _5 H! p# L& V- x. _0 o" i
% ]& |$ z( r, B1 _2 G/ ^8 b$ D* G<SCRIPT LANGUAGE="JavaScript">
+ e% x! g' |2 X' ~ function mobile_device_detect(url)* \4 [( K) J0 T3 t, z
{( k6 |) } [: H; m/ G- p, b
var thisOS=navigator.platform;
+ p6 a7 i# c/ ? var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");1 h! s( h' M1 D X
for(var i=0;i<os.length;i++)
8 j6 I" z% e% ]" u1 g4 l {; _7 P% z% a- v8 D" {
if(thisOS.match(os[i]))
( m6 i0 l% i4 ~5 v/ w$ t { 2 L6 Z9 D& \/ U& d) e9 \ U/ r4 f
window.location=url;: G- y5 Z) e, y3 H( ?
}
# g4 L7 w& U+ o/ w
. \$ }) E2 b/ b# _ }
9 z0 f+ h/ K+ g+ A6 [) }/ }) i //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
: _1 G2 e# i" v! M% p/ g if(navigator.platform.indexOf('iPad') != -1)
3 ]( Y \: t8 @/ ?( a3 o Z' c q {
- |; E' [7 _1 R) ` window.location=url;( ?' i4 t& y7 `( t2 T B" m
}! Z4 X5 @. `5 z+ n1 }' D5 x
//做这一部分是因为Android手机的内核也是Linux
& T8 T+ n# V, w //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
1 d4 r3 j. e' S7 j( e+ h var check = navigator.appVersion;
0 |0 ]% B* K9 ~. } if( check.match(/linux/i) )
& W. q& m/ ^: J- o9 h t {& G& ?, _& [. c/ O, f
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件, V3 z: ]& G$ _, c4 I* Q) x) V
if(check.match(/mobile/i) || check.match(/X11/i))
& Q+ R$ \+ r& v! Y+ A* ^, D {
1 Z& o, V4 A) D* I4 Q window.location=url;
' @9 p% ^0 F N }
8 b- \0 b& t+ n3 t9 B$ {, q }/ n: E2 _, H+ h9 w2 u' p4 w
//类in_array函数
& z. c4 M7 I) @ a* ~1 r Array.prototype.in_array = function(e)
$ [& r# \& R- q8 f {
, i9 ]- j9 t& C( a% ? for(i=0;i<this.length;i++)
. T# a6 B) R# j. y! M% C( w0 F {7 _$ O! |5 d/ I# Y& h
if(this[i] == e): i' Q# R% d/ r' [
return true;
9 T# Q1 z' _$ X' |6 m6 r. b8 T7 W }6 D) g c- \9 |4 G5 s9 y, {. v
return false;
. \0 `- u# l/ c' r8 A }
- o8 f8 J% Z2 |; g4 ? } ) \- o, j# O: u0 \2 p" y
mobile_device_detect("http://m.xxx.com");
$ @; n/ t4 o' K4 `2 f9 o# { </SCRIPT> |
|