<body leftmargin=0 topmargin=0 oncontextmenu='return false' ondragstart='return false' onselectstart ='return false' onselect='document.selection.empty()' oncopy='document.selection.empty()' onbeforecopy='return false' onmouseup='document.selection.empty()'>
二、真正的屏蔽鼠标右键
<script language="JavaScript">
<!--
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
//-->
</script>
三、
<SCRIPT LANGUAGE=javascript>
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>与<body>之间我已经调试过了 没问题
禁止保存网页
<NOSCRIPT><IFRAME src=Example132.htm></IFRAME></NOSCRIPT>
下面这段代码,就能搞定在网页中又禁止复制、又禁止键盘复制、还能禁止选择。
<script language="Javascript">
document.oncontextmenu=new Function("event.returnValue=false")
document.onselectstart=new Function("event.returnValue=false")
</script>
四、
onselect="document.selection.empty()"//禁止选中
oncopy="document.selection.empty()"//禁止复制
下面给你个演示:
<html>
<head><title>禁止右键和禁止使用复制键</title>
<script language="javascript">
function onKeyDown()
{
if ((event.keyCode==116)||(window.event.ctrlKey)||(window.event.shiftKey)||(event.keyCode==122))
{
event.keyCode=0
event.returnValue=false
}
}
function yxl() {
if(window.event.altKey)
{
window.event.returnValue=false
}
}
document.onkeydown=yxl
</script>
</head>
<!--在网页中加上下面代码//-->
<body onkeydown="onKeyDown()" oncontextmenu="return false">
嘿嘿,把我复制走吧,我跟你拉!呵呵
</body>
</html>
五、
禁止复制代码
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidthdocument.MM_pgH=innerHeightonresize=MM_reloadPage}}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload()
}
MM_reloadPage(true)
//-->
</script>
</head>
<body leftmargin=0 topmargin=0 onmousemove='HideMenu()' oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()">
<noscript><iframe src="/*>"</iframe></noscript>
在<body>标签加入onselectstart="return false"和oncontextmenu="return false"就行了,<body onselectstart="return false" oncontextmenu="return false">
onselectstart="return false"的效果是不能选择,oncontextmenu="return false"的效果是禁用鼠标右键
页面禁止使用右键和复制功能,甚至连Ctrl键也禁止掉了,这个效果是如何实现的呢?其实很简单就是调用了一段JS代码而已。下面就是实现效果所需代码:
function click(e) {
if (document.all) {
if (event.button==1||event.button==2||event.button==3) {
oncontextmenu='return false'
}
}
if (document.layers) {
if (e.which == 3) {
oncontextmenu='return false'
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN)
}
document.onmousedown=click
document.oncontextmenu = new Function("return false")
var travel=true
var hotkey=17 /* hotkey即为热键的键值,是ASII码,这里99代表c键 */
if (document.layers)
document.captureEvents(Event.KEYDOWN)
function gogo(e)
{ if (document.layers) {
if (e.which==hotkey&&travel){
alert(" *** 作错误.或许是您按错了按键!") } }
else if (document.all){
if (event.keyCode==hotkey&&travel){ alert(" *** 作错误.或许是您按错了按键!")}}
}
document.onkeydown=gogo
把上面的代码另存为一个JS文件,然后在想实现此效果的页面调用即可!
===================================================
把下列代码放到<body></body>或者<head></head>之间
<script LANGUAGE="JavaScript">
function click() { if (event.button==2)
{alert('你好,右键已被禁止使用')} } document.onmousedown=click
</script>
===================================================
禁止点击鼠标右键1:
<SCRIPT language=JavaScript>
<!--
file://锁鼠标右键和键盘CONTEXTMENU键
function click(e) {
if (document.all) {
if (event.button==2||event.button==3) { alert("欢迎光临寒舍,有什么需要帮忙的话,请与站长联系!谢谢您的合作!!!")
oncontextmenu='return false'
}
}
if (document.layers) {
if (e.which == 3) {
oncontextmenu='return false'
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN)
}
document.onmousedown=click
document.oncontextmenu = new Function("return false")
// -->
</SCRIPT>
二、禁止点击鼠标右键2:
<!--将以下代码加入HTML的<HEAD></HEAD>之间-->
<script language="javascript">
function click() {
if (event.button==2) {
alert('欢迎光临寒舍,有什么需要帮忙的话,请与站长联系!谢谢您的合作!!!')
}
}
document.onmousedown=click
</script>
三、禁止鼠标右键3(推荐):
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidthdocument.MM_pgH=innerHeightonresize=MM_reloadPage}}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload()
}
MM_reloadPage(true)
//-->
</script>
</head>
<body leftmargin=0 topmargin=0 onmousemove='HideMenu()' oncontextmenu="return false" ondragstart="return false" onselectstart
="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false"
onmouseup="document.selection.empty()">
<noscript><iframe src=*></iframe></noscript>
==============================================
自己根据要求随便选一个吧
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)