首页 | DV动态 | 数码产品 | 视频采编 | 网站建设 |
【收藏DV】
  最近3月排行
·赤马劫
·985、211、双一流
·许小年:碎片化信息让人变得无知,要少看手机多读书
·上了大学也没体面工作,我们是否还要上大学- 附一组数据
·许小年:浅析日本失去的30年——兼评“资产负债表衰退”
·高中英语-单词表
·常用网管软件下载,持续更新中...
111
2004/11/20 16:25:35
 

    有时候,我们不希望自己网页上的精美图片或者文字被别人COPY,这时候就需要禁止鼠标右键的功能。笔者收集了几种不同的方法,现拿出来和各位网页DIYer分享。


方法一:最简单的方法

 
  function click()
  { 
   if(event.button==2)
     {
        alert('右键不能用了!') 
     } 
  } 
  document.onmousedown=click 
 

    这是最简单,也是最常用的方法



方法二:添加到收藏夹

 
  function click()
  { 
     if(event.button==2)
     {
        window.external.addFavorite('http://td2shou.126.com','天地网络二手市场');
     }
  } 
  document.onmousedown=click 




方法三:使右键失效

将改成

    该方法须IE5以上



方法四:

将改成

    该方法使鼠标失效,效果和方法三差不多,但此时不能用鼠标选取页面上的内容,同时“编辑->全选”也没有作用。


方法五:定制自己的右键菜单
  
  第1步:将下面的代码加到中






function goto()

  if(event.srcElement.className=="menu2") 
  {
     if(event.srcElement.url=="reload")
        window.location.reload();
     else if(event.srcElement.url=="viewsource")
        window.location="view-source:"+window.location.href;
 else if(event.srcElement.url=="#")
    return;
 else
window.open(event.srcElement.url); 
  }

var showurl=1;
function show()

  var rightedge=document.body.clientWidth-event.clientX; 
  var bottomedge=document.body.clientHeight-event.clientY; 
  if(rightedge     menu1.style.left=document.body.scrollLeft+event.clientX-menu1.offsetWidth; 
  else
     menu1.style.left=document.body.scrollLeft+event.clientX; 
  if(bottomedge>menu1.offsetHeight) 
     menu1.style.top=document.body.scrollTop+event.clientY-menu1.offsetHeight; 
  else 
     menu1.style.top=document.body.scrollTop+event.clientY; 
  menu1.style.visibility="visible" 
  return false 


function hide()

  menu1.style.visibility="hidden"; 


function highlight()

  if(event.srcElement.className=="menu2")

     event.srcElement.style.backgroundColor="highlight"; 
     event.srcElement.style.color="white"; 
     if(showurl==1)
 {
    if(event.srcElement.url=="reload")
   window.status="刷新页面";
else if(event.srcElement.url=="viewsource")
   window.status="查看源文件";
else if(event.srcElement.url=="#")
   return;
else
   window.status=event.srcElement.url;
 }
  } 
}
 
function lowlight()

  if(event.srcElement.className=="menu2")

     event.srcElement.style.backgroundColor=""; 
     event.srcElement.style.color="black"; 
     window.status=''} 



  第2步:将下面的代码加到中

 
我的网站

 


查看源文件


 

 
  document.oncontextmenu=show; 
  if(document.all&&window.print) 
     document.body.onclick=hide; 




    其中前两种方法都能很容易地破解,后三种方法一般不易被破解,最Cool的当属第五种方法 (DVOL本文转自:中国DV传媒 http://www.dvol.cn)

欢迎关注微信公众账号:手机烟台(mYantai)

 

  上一篇:禁止鼠标右键的几种方法
  下一篇:让弹出窗口只弹出一次
      更多...
::打印本页 ::      ::关闭窗口::


版权所有© 数码在线网站 DV OnLine©  鲁ICP备12016322号-1