How to Disable the Mouse wheel click Button?

后端 未结 4 1858
借酒劲吻你
借酒劲吻你 2020-12-17 01:44

I\'m trying to find a way of disabling the default action of the mouse wheel button which is to open the link in a new tab.

Is that possible?

4条回答
  •  悲哀的现实
    2020-12-17 02:26

    Disable mouse wheel event by using JAVASCRIPT :

    In IE:

    document.attachEvent('onmousewheel', function(e){
         if (!e) var e = window.event;
         e.returnValue = false;
         e.cancelBubble = true;
         return false;
    }, false);
    

    In Safari:

    document.addEventListener('mousewheel', function(e){
        e.stopPropagation();
        e.preventDefault();
        e.cancelBubble = false;
        return false;
    }, false);
    

    In Opera:

    document.attachEvent('mousewheel', function(e){
        if (!e) var e = window.event;
        e.returnValue = false;
        e.cancelBubble = true;
        return false;
    }, false);
    

    In Firefox:

    document.addEventListener('DOMMouseScroll', function(e){
        e.stopPropagation();
        e.preventDefault();
        e.cancelBubble = false;
        return false;
    }, false);
    

提交回复
热议问题