Last active
August 29, 2015 14:13
-
-
Save mizhdi/b1fb5eea89c89529f7ba to your computer and use it in GitHub Desktop.
js:util
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 禁止iOS浏览器的橡皮筋效果,但是实例中会禁止掉链接的事件,也可以在body上加ontouchmove="event.preventDefault()" | |
$(document).ready(function(){ | |
function stopScrolling( touchEvent ) { | |
touchEvent.preventDefault(); | |
} | |
document.addEventListener( 'touchstart' , stopScrolling , false ); | |
document.addEventListener( 'touchmove' , stopScrolling , false ); | |
}); | |
//判断是否为android,BlackBerry,ios,windows | |
$(document).ready(function () { | |
var isMobile = { | |
Android: function () { | |
return navigator.userAgent.match(/Android/i) ? true : false; | |
}, | |
BlackBerry: function () { | |
return navigator.userAgent.match(/BlackBerry/i) ? true : false; | |
}, | |
iOS: function () { | |
return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false; | |
}, | |
Windows: function () { | |
return navigator.userAgent.match(/IEMobile/i) ? true : false; | |
}, | |
any: function () { | |
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows()); | |
} | |
}; | |
if (isMobile.any()) { | |
//要执行的代码 | |
} | |
}); | |
// 如何判断微信内置浏览器 | |
function is_weixin(){ | |
var ua = navigator.userAgent.toLowerCase(); | |
if(ua.match(/MicroMessenger/i)=="micromessenger") { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment