|
发表于 2016-11-29 22:00:21
|
显示全部楼层
加个手机版跳转代码就行。pc的就不会跳。
4 `5 u$ F* Q4 P5 V+ u) h x8 y1 j
/ o% {3 L8 F& O0 ?<SCRIPT LANGUAGE="JavaScript">/ b9 _; Z9 b1 M$ Q- [
function mobile_device_detect(url), o$ Z) G" ^* D% P- i0 O! I G% T
{9 I& ?. O6 \3 ^- L5 G( R
var thisOS=navigator.platform;% T; E- v' q; u0 r T9 y# h" ]
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
+ a& e$ V8 ` A% b& r for(var i=0;i<os.length;i++)
" s6 x1 Y: o( Y! v! w- } {0 f1 ^/ f4 f5 ?% y* S" s6 x- `; B8 J
if(thisOS.match(os[i]))2 O4 \/ j* m" B0 d
{
2 z( ]1 _3 P2 @& c/ r4 x window.location=url;
- w: Z- W1 C4 q! n% a }+ S2 C0 K2 c# U2 H- z& A; O
& V1 L8 y. T: ]1 A' F: a: D }/ q* B3 U! R7 ?% f
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认$ L3 }7 e- T: A6 o
if(navigator.platform.indexOf('iPad') != -1)$ I8 M) u4 l8 G) v( M2 k
{
( n4 _: ?7 @4 u% L* | window.location=url;
% U/ J- E/ P0 y/ D' T/ \- _4 ]! Q }
0 e0 w0 F8 |: Y# J; e$ d //做这一部分是因为Android手机的内核也是Linux, @. G6 H8 Y, |) L
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
8 b: R& V/ n z5 Q* ]( T, w var check = navigator.appVersion;8 A/ z. I2 o3 U7 C0 B; n
if( check.match(/linux/i) )
* T* V) Y# k# l4 x+ ] {( h- G$ B/ U9 d/ ^
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
! H6 ?, X" }' m if(check.match(/mobile/i) || check.match(/X11/i))( @! \" ?2 |9 H7 k- }5 Y3 a
{
6 j. y: E M! ? G$ W- P4 X window.location=url;
( q' `% q8 r0 j6 {( p }
! R- {; |+ ~' j6 `- P }8 H3 m! R1 c: R) C
//类in_array函数
7 M/ [2 @8 Y7 ~; t" z W Array.prototype.in_array = function(e)7 ?' Q% K5 P5 N; W2 y
{
( ?, ]: o8 ^9 e$ b8 q. }9 m( c for(i=0;i<this.length;i++)
3 J% Q# a, w: Q& U+ B r- e) n {+ d- C3 J! a" ~% T) B7 z
if(this[i] == e)
7 Z) G$ M7 V- i# | return true;
/ N: `. @) E5 n. R }
" I4 ^4 [( G5 i' _ return false;, a2 [+ I' Q3 X7 x# k) u4 l
}
7 ~, ]3 ~' Y4 C2 j0 F/ K ~ }
/ D! T7 k: _9 K0 e7 h mobile_device_detect("http://m.xxx.com");
' r" z$ F& C6 F8 h. c </SCRIPT> |
|