|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。' M( |$ t9 \- D' G9 `$ K
- w. e/ M$ ]! O3 ]. y<SCRIPT LANGUAGE="JavaScript">
1 X3 y8 j# i z% |' \* ~ function mobile_device_detect(url)
0 G! Z, o! c3 y; u0 R2 {, o {# O; j: y" f$ a( B
var thisOS=navigator.platform;
! G. Y$ K0 g, _ var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
9 G. ~- x' h; y for(var i=0;i<os.length;i++)
2 ^& j$ _ {* j& g) ~) S- v& \ {3 M% I: [0 e8 K- `2 G+ ~
if(thisOS.match(os[i])). z1 k* w( |7 q
{ # b% w$ Z% e8 V! u
window.location=url;
; P$ r# X9 [' l- q- P) ` m: O }6 d/ O2 E' z, Y% C# f2 _
2 N. U7 M7 r: V+ X }! {1 W: [5 a# {! a. z
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认 ?; `) ]5 h# Z8 `) g4 c7 |
if(navigator.platform.indexOf('iPad') != -1)
: ]0 i" q3 P4 q! I {
$ n) u5 ]+ ~ ?% q8 v window.location=url;
+ f1 y* f+ p' c( P, G1 v' Q0 w }1 K# K5 C9 ]/ x
//做这一部分是因为Android手机的内核也是Linux
6 v2 U0 }# G- K. ^, Z //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
2 \+ h; f7 o& F7 ^' L" E! Q b var check = navigator.appVersion;
. M& @' N9 a( z4 I/ T9 j9 h- D if( check.match(/linux/i) )4 Q# l5 K* H. U0 U7 [
{7 y/ S: j- A6 G) M+ g. ~
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
- z: }# O4 r2 q& w1 w9 @. q& C: ] if(check.match(/mobile/i) || check.match(/X11/i))! {! ?6 d3 Z# ^6 W" t
{
5 M, c% M' j7 t window.location=url;
' }8 e; h) ~, _" W }
5 w# l8 F P. L2 o+ ?; l }2 f4 P @1 Z% z( C1 [3 }9 Y% t
//类in_array函数
- ~3 u% C b" A( X Array.prototype.in_array = function(e)' ^1 @) U5 z% P- c
{
; ]' X# y" z; p0 [6 E0 W for(i=0;i<this.length;i++)
$ M! H- Z+ B, z! ^8 N5 v+ N. L8 |5 G- R {
2 s. f! J7 G1 K4 ?) p9 {$ ? if(this[i] == e)- |" o+ K3 } o `2 R
return true;# x4 c1 z$ k$ }* \! D0 E
}
9 }' `1 t, W7 K/ ~, k1 a2 z- r return false;
0 W" q) d( n- C- Y: a. \. o }
9 N4 k5 o/ k/ | G( s0 ?3 h } & k( t6 s8 I6 M# p" e0 N" p
mobile_device_detect("http://m.xxx.com");/ ~5 p, @' P' L
</SCRIPT> |
|