JavaScript代码实现禁止右键、禁选择、禁粘贴、禁shift、禁ctrl、禁alt
作者:mrr 时间:2024-04-18 09:39:57
废话不多说了直接给大家贴代码了。
代码如下:
<script language="JavaScript">
<!--
//js禁用某些键的代码
//www.aspxhome.com
function key(){
if(event.shiftKey){
window.close();}
//禁止Shift
if(event.altKey){
window.close();}
//禁止Alt
if(event.ctrlKey){
window.close();}
//禁止Ctrl
return false;}
document.onkeydown=key;
if (window.Event)
document.captureEvents(Event.MOUSEUP);
function nocontextmenu(){
event.cancelBubble = true
event.returnValue = false;
return false;}
function norightclick(e){
if (window.Event){
if (e.which == 2 || e.which == 3)
return false;}
else
if (event.button == 2 || event.button == 3){
event.cancelBubble = true
event.returnValue = false;
return false;}
}
//禁右键
document.oncontextmenu = nocontextmenu; // for IE5+
document.onmou<a href="https://www.aspxhome.com/article/1141.html" target="_blank" class="infotextkey">sed</a>own = norightclick; // for all others
//-->
</script>
<body onselectstart="return false"; onpaste="return false";>
1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键特效
<table border oncontextmenu=return(false)><td>no</table> 可用于Table
2. <body onselectstart="return false"> 取消选取、防止复制
3. onpaste="return false" 不准粘贴
4. oncopy="return false;" oncut="return false;" 防止复制
PS:JS防止后退,刷新,关闭的解决办法
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title> New Document </title>
</head>
<script language="javascript">
function RunOnBeforeUnload() {window.onbeforeunload = function(){ return '将丢失未保存的数据!'; } }
</script>
<body onload="RunOnBeforeUnload()">
刷新,关闭,后退,F5 测试
</body>
</html>
虽然onbeforeunload这个事件已经Web标准被淘汰,但目前能实现这个效果的也就只有这个事件.还好浏览器都能很好的支持.
测试结果:
IE6.0,FireFox,Chrome通过
标签:右键,shift,ctrl,alt
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Bootstrap学习笔记之css样式设计(1)
2024-04-26 17:15:01
![](https://img.aspxhome.com/file/2023/0/135620_0s.png)
如何使用FSO修改文件夹的名称
2008-10-11 14:24:00
vant之van-list的使用及踩坑记录
2023-07-02 16:48:41
![](https://img.aspxhome.com/file/2023/8/139788_0s.png)
Python List列表对象内置方法实例详解
2023-08-21 12:49:58
Python流程控制 while循环实现解析
2023-02-07 04:16:33
![](https://img.aspxhome.com/file/2023/9/86179_0s.jpg)
JS正则(RegExp)判断文本框中是否包含特殊符号
2023-05-12 18:18:55
httpwatch 的页面元素加载时间表
2008-02-13 08:28:00
![](https://img.aspxhome.com/file/UploadPic/20082/13/200821383430675s.gif)
Python的randrange()方法使用教程
2021-02-08 10:22:22
Golang开发命令行之flag包的使用方法
2024-02-16 09:26:04
![](https://img.aspxhome.com/file/2023/0/105110_0s.png)
服务端XMLHTTP(ServerXMLHTTP in ASP)基本应用(上)
2008-11-11 12:49:00
![](https://img.aspxhome.com/file/UploadPic/200811/11/63u9_google-92s.png)
将python文件打包成EXE应用程序的方法
2022-07-09 16:01:12
![](https://img.aspxhome.com/file/2023/5/123685_0s.jpg)
MySQL 索引详解
2010-01-20 09:39:00
XHTML代码的基本应用
2007-10-26 12:32:00
让你的主页声色并茂—巧为网页添加背景音乐
2010-09-02 12:35:00
![](https://img.aspxhome.com/file/UploadPic/20072/200723113013157s.jpg)
sqlserver2005使用row_number() over分页的实现方法
2024-01-18 20:01:02
javascript 将共享属性迁移到原型中去的实现方法
2024-04-22 13:05:00
详解python连接telnet和ssh的两种方式
2023-02-10 01:27:14
Python实现Youku视频批量下载功能
2022-08-14 21:16:45
![](https://img.aspxhome.com/file/2023/0/105440_0s.png)
教你使用Python pypinyin库实现汉字转拼音
2021-10-03 16:48:36
![](https://img.aspxhome.com/file/2023/1/109341_0s.png)
mysql中截取字符串的6个函数讲解
2024-01-13 13:54:11
![](https://img.aspxhome.com/file/2023/9/118159_0s.png)