How to disable mouse gestures in edge browser with JavaScript? system win10;browser version 114.0.1823.51

权鑫 0 Reputation points
2023-06-19T12:03:24.1766667+00:00

I want to disable mouse gestures in edge browser with JavaScript,Because it interferes with my right-drawing function

I tried some event monitoring, but it didn't work

<!doctype html>
<html lang='en'>
<head>
  <meta charset='UTF-8'>
  <meta name='viewport'
        content='width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0'>
  <meta http-equiv='X-UA-Compatible' content='ie=edge'>
  <title>edge mouse gestures</title>
</head>
<body>

<script>
  const fn = (e) => {
    e.preventDefault()
    e.stopPropagation()
  }
  document.addEventListener('mousedown', fn)
  document.addEventListener('contextmenu', fn)
  document.addEventListener('mousemove', fn)
  document.addEventListener('touchstart', fn, false)
  document.addEventListener('touchend', fn, false)
  document.addEventListener('touchmove', fn, false)
  window.addEventListener('mousedown', fn)
  window.addEventListener('contextmenu', fn)
  window.addEventListener('mousemove', fn)
  window.addEventListener('touchstart', fn, false)
  window.addEventListener('touchend', fn, false)
  window.addEventListener('touchmove', fn, false)
</script>
</body>
</html>

So,Are there any apis you can control?

Microsoft Edge Microsoft Edge development
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    2023-06-20T06:38:04.6833333+00:00

    Hi @权鑫,

    I want to disable mouse gestures in edge browser with JavaScript,Because it interferes with my right-drawing function

    As far as I know, for security reasons, JavaScript cannot implement such a requirement, and it does not have access to the operating system. And for your needs, it is equivalent to modifying the browser settings (modifying the files in the hard disk), which poses a great security risk.

    If you need to enable or disable this feature, please navigate to the Customize browser section in the edge://settings/appearance page and modify the corresponding section options.

    In addition, I found the same question on Stack overflow, if they all posted by you, I will follow you on Q&A. Thank you for your understanding.

    Best regards,

    Xudong Peng


    If the answer is the right solution, please click "Accept Answer" and kindly upvote. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. 2023-06-20T07:39:31.58+00:00

    To disable mouse gestures in Edge Browser with JavaScript, you can use the following code:

    
    var nav = window.navigator.userAgent.toLowerCase();
    
    var isEdge(isEdge) {
    
      document.addEventListener("mousewheel", function(e) {
    
        if (e.ctrlKey) {
    
          e.preventDefault();
    
        }
    
      }, { passive: false });
    
    }
    
    

    This code adds an event listener to the `mousewheelvar isEdge = (nav.indexOf('edge') > -1);

    if (isEdge) {

    document.addEventListener("MSPointerMove", function(e) {

    if (e.pointerType === "mouse" && e.getIntermediatePoints().length > 1) {
    
      e.preventDefault();
    
    }
    

    }, {passive: false});

    }

    
    This code first detects if the browser is Edge by checking the user agent string. If Edge is detected, then an event listener is added to the document that listens for MSPointerMove events (which are the events used for Edge's mouse gestures). If the event is a mouse input and has multiple intermediate points, then the preventDefault() method is called to disable the gesture.
    
    Note that this code may not work in future versions of Edge, as Microsoft may change the way their mouse gestures work.
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.