js禁止右键、复制、粘贴、另存为等功能代码
1、对整个网页限制鼠标右键:
oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键,其实是禁止快捷菜单,因为不光右键可以弹出这个菜单,键盘上空格键右边的windows键也可以激活这个快捷菜单。
<table border oncontextmenu=return(false)> <td> no</table> 可用于Table
function click() {
if (event.button==2) {
alert('对不起,本页禁用右键!')
}
}
document.onmousedown=click
2、禁止鼠标右键:oncontextmenu="return false";
3、禁止选择:onselectstart="return false"; <body onselectstart="return false"> 整个网页禁止选取、防止复制
4、禁止拖放:ondragstart="return false";
5、禁止拷贝:oncopy=document.selection.empty() 。
6、禁止复制和剪切:oncopy="return false;" oncut="return false;"
7、禁止保存:<noscript><iframe src="*.htm"></iframe></noscript>,放在head里面。
8、禁止粘贴:<input type=text onpaste="return false">
9、关闭输入法:<input style="ime-mode:disabled">
10、屏蔽打印:
<style>
@media print{
* {display:none}
} </style>
11、禁止查看源文件:
<html>
<head>
<script>
function clear(){
Source=document.body.firstChild.data;
document.open();
document.close();
document.title=”看不到源代码”;
document.body.innerHTML=Source;
}
clear();
</script>
12、图片禁止右键保存:
把下面代码放在<head>和</head>之间
<script >
function click() {
alert(‘对不起,您不能保存此图片,谢谢您的理解和支持!’) }
function click1() {
if (event.button==2) {alert(‘对不起,您不能保存此图片,谢谢您的理解和支持!’) }}
function CtrlKeyDown(){
if (event.ctrlKey) {alert(‘不当的拷贝将损害您的系统!’) }}
document.onkeydown=CtrlKeyDown;
document.onselectstart=click;
document.onmousedown=click1;
</script>
</head>
13、网页禁止另存为:
<noscript><iframe src=”/blog/*.html>”;</iframe></noscript>
禁止被frame调用:
<script >if (top.location != self.location)top.location=self.location;</script>
14、禁shift、禁ctrl、禁alt
<script>
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.onmousedown = norightclick; // for all others
key();
</script>
参考资料:
1、http://www.oschina.net/code/snippet_262017_19272
2、http://www.jb51.net/article/23077.htm
3、http://www.ithao123.cn/content-8054668.html
4、http://www.chhua.com/web-note2825
5、http://blog.csdn.net/yj451928923/article/details/7094628