Home >Web Front-end >JS Tutorial >Can You Really Disable Right-Clicking on Your Website?
Disable Right Click on Web Pages
Can you prevent users from right-clicking on your web page? The answer is yes and no.
No, Without JavaScript
Unfortunately, disabling right-click without JavaScript is not possible. Most browsers allow users to disable JavaScript, rendering such a solution ineffective.
Yes, With JavaScript
To disable right-click using JavaScript, you can add an event listener for the "contextmenu" event and call the preventDefault() method:
document.addEventListener('contextmenu', event => event.preventDefault());
But Wait, There's a Catch
Despite the possibility of disabling right-click via JavaScript, it's strongly discouraged. Why?
The above is the detailed content of Can You Really Disable Right-Clicking on Your Website?. For more information, please follow other related articles on the PHP Chinese website!