Prevent middle mouse click scrolling

三世轮回 提交于 2019-11-28 10:46:27

Use:

$('body').mousedown(function(e){if(e.button==1)return false});

This works on Chrome: http://jsfiddle.net/PKpBN/3/

There's no need to include jQuery just for this.

If you are using jQuery, there are already some great answers here. If not, you can use vanilla JS:

document.body.onmousedown = function(e) { if (e.button === 1) return false; }

Try using return false; instead of e.preventScrolling();

Rajmahendra
document.body.style.overflow=allowScroll?"":"hidden";

If you want to stop scrolling completely, here is the required code:

window.onscroll = function() {
    document.body.scrollTop = 0;
}

This will effectively disable the middle button as well..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!