Skip to content

Instantly share code, notes, and snippets.

@mizhdi
Last active August 29, 2015 14:13
Show Gist options
  • Save mizhdi/2dcf80bc53962b32497d to your computer and use it in GitHub Desktop.
Save mizhdi/2dcf80bc53962b32497d to your computer and use it in GitHub Desktop.
util
// 禁止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