如何禁用鼠标右键单击网页? [英] How to disable mouse right click on a web page?

查看:114
本文介绍了如何禁用鼠标右键单击网页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想禁用鼠标右键单击HTML页面。
我有一个页面,用户必须输入详细信息。
我不希望用户看到用鼠标右键单击显示的菜单。相反,我想显示一个自定义菜单。我知道有一些插件可以做到这一点。但是我的需求不需要任何插件。

解决方案

这是不专业的,无论如何这将启用JavaScript:

  document.oncontextmenu = document.body.oncontextmenu = function(){return false;} 

您可能还想在返回false之前向用户显示一条消息。



然而,我必须说这不应该做一般,因为它限制用户的选择而不解决问题(事实上,上下文菜单可以很容易地再次启用。)。

下面的文章更好地解释为什么不应该这样做,以及可以采取哪些其他行动来解决常见的相关问题:
http://articles.sitepoint.com/article/dont-disable-right-click


I want to disable mouse right click on an HTML page. I have a page where user has to enter the details. I don't want the user to see the menu thats get displayed with the mouse right click. Rather I want to display a custom menu. I know there are some plugins available to do that. But my requirement does not need any plugins.

解决方案

It's unprofessional, anyway this will work with javascript enabled:

document.oncontextmenu = document.body.oncontextmenu = function() {return false;}

You may also want to show a message to the user before returning false.

However I have to say that this should not be done generally because it limits users options without resolving the issue (in fact the context menu can be very easily enabled again.).

The following article better explains why this should not be done and what other actions can be taken to solve common related issues: http://articles.sitepoint.com/article/dont-disable-right-click

这篇关于如何禁用鼠标右键单击网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆