<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<TITLE>Popup对象实现右键菜单</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="JavaScript">
var oPopup = window.createPopup();
function contextMenu()
{var left = event.offsetX + 10;
var top = event.offsetY + 10;
oPopup.document.body.innerHTML = oContext.innerHTML; 
oPopup.show(left, top, 120, 80, window.document.body);}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body oncontextmenu="contextMenu(); return false;">
<h1>Popup对象实现右键菜单</h1>
单击鼠标右键查看效果
<div ID="oContext" style="DISPLAY: none; BACKGROUND: #e4e4e4; ">
<div onmouseover="this.style.background='gold'" 
onmouseout="this.style.background='#e4e4e4'" 
<span onclick='parent.location.href="http://www.zol.com.cn"'>
中关村在线</span> 
</div>
<div onMouseOver="this.style.background='gold'" 
onmouseout="this.style.background='#e4e4e4'" >
<span onClick="parent.location.href='http://www.cfan.com.cn'">
电脑爱好者</span> 
</div>
<div onMouseOver="this.style.background='gold';" 
onmouseout="this.style.background='#e4e4e4';">
<span onClick="parent.location.href='http://www.sina.com.cn'">
新浪网</span> 
</div>
<div onMouseOver="this.style.background='gold'" 
onmouseout="this.style.background='#e4e4e4'" >
<span onClick="parent.location.href='http://www.webjx.com'">
我爱DivCSS</span> 
</div></div>
</body>
</html>

解决方案 »

  1.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <TITLE>Popup对象实现右键菜单</TITLE>
    <script language="JavaScript">
    var oPopup = window.createPopup();
    function contextMenu()
    {var left = event.offsetX + 10;
    var top = event.offsetY + 10;
    oPopup.document.body.innerHTML = oContext.innerHTML; 
    oPopup.show(left, top, 120, 80, window.document.body);}
    </script>
    <body oncontextmenu="contextMenu(); return false;">
    <h1>Popup对象实现右键菜单</h1>
    单击鼠标右键查看效果
    <div ID="oContext" style="DISPLAY: none;">
    <div style="BACKGROUND: #e4e4e4;border:solid 1px black;">
    <div onmouseover="this.style.background='gold'" 
    onmouseout="this.style.background='#e4e4e4'">
    <a href="http://www.svnhost.cn">开源社区</a>
    </div>
    <div onMouseOver="this.style.background='gold'" 
    onmouseout="this.style.background='#e4e4e4'" >
    <a href="http://www.svnhost.cn">开源社区</a>
    </div>
    <div onMouseOver="this.style.background='gold';" 
    onmouseout="this.style.background='#e4e4e4';">
    <a href="http://www.svnhost.cn">开源社区</a>
    </div>
    <div onMouseOver="this.style.background='gold'" 
    onmouseout="this.style.background='#e4e4e4'" >
    <a href="http://www.svnhost.cn">开源社区</a>
    </div>
    </div>
    </div>
    </body>
    </html>
      

  2.   

    execCommandbSuccess = object.execCommand(sCommand [, bUserInterface] [, vValue])Copy 将当前选中区复制到剪贴板。 
    Cut 将当前选中区复制到剪贴板并删除之。 
    Delete 删除当前选中区。  
    Paste 用剪贴板内容覆盖当前选中区。 
      

  3.   

    <html> 
    <head>  
      <meta http-equiv="content-type" content="text/html;charset=gb2312" />
      <title>Menu</title>
      <style type="text/css">
      body{ font-size:12pt;}
      div.p{ background-color:#cccccc;}
      div.item{cursor:hand;color:Blue;font-size:10pt;}
      div.focus{cursor:hand;color:Red;font-size:10pt;}
      </style>
    </head> 
    <body> 
    <div id="divMenu" onselect="return false" class="p" style="position:absolute;border:solid 1px black;width:50px;display:none">
    <div onselect="return false" class="item" onclick="Exec('cut')" onmouseover="this.className='focus'" onmouseout="this.className='item'">剪切</div>
    <hr />
    <div onselect="return false" class="item" onclick="Exec('copy')" onmouseover="this.className='focus'" onmouseout="this.className='item'">复制</div>
    <hr />
    <div onselect="return false" class="item" onclick="Exec('paste')" onmouseover="this.className='focus'" onmouseout="this.className='item'">粘贴</div>
    <hr />
    <div onselect="return false" class="item" onclick="Exec('delete')" onmouseover="this.className='focus'" onmouseout="this.className='item'">删除</div>
    <hr />
    <div onselect="return false" class="item" onclick="document.execCommand('SelectAll')" onmouseover="this.className='focus'" onmouseout="this.className='item'">全选</div>
    </div>
    <script type="text/javascript">
    String.prototype.trim=function(){return this.replace(/^\s*|\s*$/g,"");}
    function $(id){return document.getElementById(id);}
    var rng;
    document.oncontextmenu=function()
    {
      var d=$('divMenu');
      d.style.left=event.clientX+10+"px";
      d.style.top=event.clientY+10+"px";
      d.style.display='';
      rng=document.selection.createRange();//保存Range对象
      return false;//取消系统的菜单
    }
    function Exec(cmd)
    {
      rng.execCommand(cmd);//执行命令
    }
    document.onclick=function()
    {
        HideMenu();
    }
    function HideMenu()
    {
      $('divMenu').style.display='none';
    }
    </script>
    "网页内容" 
    <input type="text" />
    </body> 
    </html> 
      

  4.   

    嘿嘿~!~!谢谢大家哈~!~再问个问题: 怎么屏蔽ctrl+N 键啊?
      

  5.   

    <script>
    document.onkeydown=function(e)
    {
      e=e||event;
      if(e.ctrlKey&&e.keyCode==78)
      {
          if(e.preventDefault)//ff
             e.preventDefault();
          else//ie
          {
            e.keyCode=0;
            e.returnValue=false;
          }
      }
    }
    </script>