<!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>
<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>
解决方案 »
- ExtJS Gridpanel分页以及绑定数据问题
- jquery.validata.js里面像乱码似的东西是什么?
- 查找IE插件的问题
- JS打印问题。。高手的进
- FF是可以,但IE下什么也没有
- 用document.frames['myframe'].location.reload(true)刷新iframe时提示"权限不够",如何解决?
- IE6下,javascript控制input获取焦点时突出显示,异常
- 急:一个根据年、月份来决定月的天数问题
- Checkbox的BUG问题
- 用window.open 弹出最大化窗口应如何设置参数?
- 讨论下callback传递参数问题
- 如何用 js 查找 框架内的内容?
<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>
Cut 将当前选中区复制到剪贴板并删除之。
Delete 删除当前选中区。
Paste 用剪贴板内容覆盖当前选中区。
<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>
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>