<form id="form1">
<iframe style="display:none" name="ifm0">
</form>
<script>
function document.oncontextmenu(){event.returnValue=false;}
function click(){
if(event.button==2){
newpage=ifm0.showModelessDialog("javascript:alert('您好,现在点击了右键');window.close();","","status:no;resizable:no;help:no;dialogHeight:30px;dialogWidth:40px;");
setTimeout("ifm0.location.reload();",2000);
}
if(event.button==1){
newpage=ifm0.showModelessDialog("javascript:alert('您好,您点击了左键');","","status:no;resizable:no;help:no;dialogHeight:30px; dialogWidth:40px;");
setTimeout("ifm0.location.reload()",2000);
}
}
document.onmousedown=click;
</script>
<iframe style="display:none" name="ifm0">
</form>
<script>
function document.oncontextmenu(){event.returnValue=false;}
function click(){
if(event.button==2){
newpage=ifm0.showModelessDialog("javascript:alert('您好,现在点击了右键');window.close();","","status:no;resizable:no;help:no;dialogHeight:30px;dialogWidth:40px;");
setTimeout("ifm0.location.reload();",2000);
}
if(event.button==1){
newpage=ifm0.showModelessDialog("javascript:alert('您好,您点击了左键');","","status:no;resizable:no;help:no;dialogHeight:30px; dialogWidth:40px;");
setTimeout("ifm0.location.reload()",2000);
}
}
document.onmousedown=click;
</script>

本文介绍了一种通过JavaScript禁用网页上的右键菜单并处理鼠标点击事件的方法。利用iframe和showModelessDialog实现自定义警告框,同时通过document.oncontextmenu及document.onmousedown事件阻止默认上下文菜单出现,并区分左右键点击行为。
4889

被折叠的 条评论
为什么被折叠?



