|
|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。2 v( b: X% c; z( A% g5 R
2 E' f4 ^% L& }- a& u1 X2 X<SCRIPT LANGUAGE="JavaScript">/ O& v1 q' a8 [. t% A: x& O1 J ?' ?6 V
function mobile_device_detect(url)
# f. s. a/ n" S7 | {
: e3 b4 {" Y+ S1 Y: {; g4 q var thisOS=navigator.platform;4 s8 @& B0 ?7 Z% I. a* `# 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");1 N2 }1 s8 s8 i7 K
for(var i=0;i<os.length;i++)6 W4 ]9 k5 `6 D$ Y7 u
{" P }' ~% Z7 i
if(thisOS.match(os[i]))
+ f+ G% U6 {) }% S4 p8 H0 w1 G { 7 |, B' U8 d, \$ ]+ ^2 z/ w
window.location=url;% M- {/ ]/ `7 m8 W, U$ {2 d# w
}
% F7 P( S2 V( t" k/ u% ~' p , C# b7 ]) J y, h( a' _4 k
}
/ d: {9 J0 _7 c6 L$ _0 F //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认/ N$ E8 M3 s/ J8 m8 E" H
if(navigator.platform.indexOf('iPad') != -1)
$ U: P9 A# _0 _( R {
( G l, G/ x4 w6 N* V c* L0 t window.location=url;8 `* r& R3 G, |! @
}
5 M; S5 E' H& F+ ] //做这一部分是因为Android手机的内核也是Linux
o0 G/ j, Y# z! H- ]8 i. Z5 ` //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断" N. y4 n4 g6 }& W5 ?
var check = navigator.appVersion;, p. g% t$ B* U4 J/ k! k: [
if( check.match(/linux/i) )
; h @# y1 _8 I# A9 m5 ~ {
# |1 q5 {" O6 O# u9 y5 g/ D //X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件* a6 ~4 z+ l8 F v* `
if(check.match(/mobile/i) || check.match(/X11/i))! f% r/ g) G; C2 f* n
{
0 W. W+ c& _6 u, r( Q, x! m window.location=url;/ W0 ~# k1 c& M) k
}
8 m2 k& G# W( F' i }
* d9 |; W# A, ^7 f3 q3 n: O! U, ^. W //类in_array函数
5 s/ F0 E3 j* O: B8 P Array.prototype.in_array = function(e): G& r+ D: T% d) \
{
* _7 U8 v) N w& Z+ h3 X- G for(i=0;i<this.length;i++)
; k# n) W0 c4 j6 w; w {
2 m3 C5 W& \- |/ e! Q: u if(this[i] == e) c) i7 [( y/ p
return true;5 v% l0 Q' S, o: k6 [- i
}0 J/ U. L1 V u0 }
return false;; u& Q* C6 W" J9 g0 P
}
- X. N( O8 B* `3 @3 Y8 u( P }
9 d5 l7 P* J3 y) P0 ^ mobile_device_detect("http://m.xxx.com");
7 ~0 E: ?5 _; _0 c$ s. a: a </SCRIPT> |
|