How to use code (CSS or JS) to disable mouse right-click gesture in edge?

BeiFuSheng 0 Reputation points
2025-06-19T07:44:49.3566667+00:00

My project includes 3D modeling related functions, where the right mouse button is bound to functions such as camera or model translation in 3D, but edge gestures override my own code functions.

Is there any way to program code in HTML to disable the right mouse button gesture on edge?

just like this:

{AD54FB67-9BFB-4985-8486-F893250EB265}

Microsoft Edge Microsoft Edge development
{count} votes

1 answer

Sort by: Most helpful
  1. Damien Pham (WICLOUD CORPORATION) 80 Reputation points Microsoft External Staff
    2025-06-20T09:39:07.35+00:00

    Hello BeiFuSheng,


    Many modern browsers, including Microsoft Edge, have built-in security features that prevent websites from disabling the right-click functionality. This is primarily due to concerns around user autonomy and security risks. Disabling right-click has historically been used by some websites to prevent users from accessing browser features like "Inspect Element" or saving images, but this practice is generally discouraged.

    Why Browsers Disallow Disabling Right-Click

    User Experience: Right-click is a fundamental part of browser navigation. Disabling it can frustrate users and degrade their experience.

    Security Concerns: Preventing right-click can be used to obscure malicious behavior, such as hiding scripts or preventing inspection of suspicious elements.

    Accessibility: Many accessibility tools rely on right-click functionality. Disabling it can interfere with assistive technologies.

    Developer Tools Access: Browsers aim to keep developer tools accessible to users for debugging and learning purposes.

    Microsoft Edge and Other Browsers

    Microsoft Edge, like Chrome and Firefox, adheres to modern web standards that prioritize user control. Even if a developer uses JavaScript to disable right-click (e.g., document.addEventListener('contextmenu', event => event.preventDefault());), browsers may override this behavior or allow users to disable such scripts through settings or extensions.
    For further information, you can refer to this thread: https://stackoverflow.com/questions/737022/how-do-i-disable-right-click-on-my-web-page


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.