您现在的位置: 365建站网 > 365文章 > html+css中让网页禁止右键菜单的方法

html+css中让网页禁止右键菜单的方法

文章来源:365jz.com     点击数:2570    更新时间:2020-09-20 14:58   参与评论

通过javascript来实现:

oncontextmenu               右键菜单事件
onselectstart                   选中网页内容事件
oncopy                           复制网页内容事件

写法1:

<script type="text/javascript">document.oncontextmenu = function(){return false;};</script>
写法2:  
也可以直接在<body>标签上添加属性,如:java代码
<body οncοntextmenu="return false">
效果一样。明白了上面的原理,也就找到了破解的方法,如下:在浏览器地址栏(或者 Ctrl + O)输入以下代码:

 

javascript:alert(document.onselectstart = document.οncοntextmenu= document.onmousedown = document.onkeydown = function(){return true;});


通过css中让网页禁止右键菜单的方法:

           -webkit-touch-callout: none; /*系统默认菜单被禁用*/
          -webkit-user-select: none; /*webkit浏览器*/
          -khtml-user-select: none; /*早起浏览器*/
          -moz-user-select: none; /*火狐浏览器*/
          -ms-user-select: none; /*IE浏览器*/
          user-select: none; /*用户是否能够选中文本*/


/*设置IOS页面长按不可复制粘贴,但是IOS上出现input、textarea不能输入,因此将使用-webkit-user-select:auto;*/

 *{  
 -webkit-touch-callout:none; 
 /*系统默认菜单被禁用*/ 
 -webkit-user-select:none; 
 /*webkit浏览器*/
 -khtml-user-select:none; 
 /*早期浏览器*/
 -moz-user-select:none;
 /*火狐*/   
 -ms-user-select:none; 
 /*IE10*/
 user-select:none;
 }
 input,textarea {
 -webkit-user-select:auto; 
 /*webkit浏览器*/ 
 margin: 0px;
 padding: 0px;
 outline: none;
 }


如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛

发表评论 (2570人查看0条评论)
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
昵称:
最新评论
------分隔线----------------------------

快速入口

· 365软件
· 杰创官网
· 建站工具
· 网站大全

其它栏目

· 建站教程
· 365学习

业务咨询

· 技术支持
· 服务时间:9:00-18:00
365建站网二维码

Powered by 365建站网 RSS地图 HTML地图

copyright © 2013-2024 版权所有 鄂ICP备17013400号