加入收藏 | 设为首页 | 会员中心 | 我要投稿 聊城站长网 (https://www.0635zz.com/)- 智能语音交互、行业智能、AI应用、云计算、5G!
当前位置: 首页 > 教程 > 正文

JavaScript禁止页面操作的实例代码

发布时间:2023-08-29 14:57:35 所属栏目:教程 来源:
导读:单的JS禁止页面右键菜单--避免网站信息被盗用

代码如下:

<script type="text/javascript">

function block(oEvent){

if(window.event)

oEvent=window.event;

if(oEvent.button=
单的JS禁止页面右键菜单--避免网站信息被盗用
 
代码如下:
 
<script type="text/javascript">
 
  function block(oEvent){
 
   if(window.event)
 
    oEvent=window.event;
 
   if(oEvent.button==2)
 
    alert("鼠标右键不可用");
 
  }
 
  document.onmousedown=block;
 
</script>
 
网页上禁止复制主要靠JavaScript来实现。
 
<BODY oncontextmenu="return false" onselectstart="return false"
 
ondragstart="return false" onbeforecopy="return false" oncopy=document.selection.empty() onselect=document.selection.empty()>
 
-----------------------------------------------
 
防止复制的js
 
-----------------------------------------------
 
代码如下:
 
<SCRIPT language=JavaScript1.2>
 
function disableselect(e){
 
return false}
 
function reEnable(){return true
 
}
 
file://if IE4+
 
document.onselectstart=new Function ("return false")
 
file://if NS6
 
if (window.sidebar){
 
document.onmousedown=disableselect
 
document.onclick=reEnable
 
}
 
</SCRIPT>
 
<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=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
 
    else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
 
}
 
MM_reloadPage(true);
 
//-->
 
</SCRIPT>
 
-------------------------------------------------------
 
防止下载的js
 
-------------------------------------------------------
 
<noscript><iframe src=""></iframe></noscript>
 
--------------------------------------------------------
 
下面是防止右键的js:
 
代码如下:
 
<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>
 
<title>CSS禁止选择和复制</title>
 
<meta http-equiv="content-Type" content="text/html;charset=gb2312">
 
<style>
 
body{
 
 -moz-user-select:none;
 
 hutia:expression(this.onselectstart=function(){return(false)});
 
 

(编辑:聊城站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章