您是否考虑过用 javascript 编写自己的上下文菜单?只需听用户右键单击正文,然后使用复制和粘贴命令显示您的菜单(提示:element.style.display = "block|none")。要复制,请执行以下代码:
CopiedTxt = document.selection.createRange();
CopiedTxt.execCommand("Copy");
并粘贴:
CopiedTxt = document.selection.createRange();
CopiedTxt.execCommand("Paste");
来源:
http://www.geekpedia.com/tutorial126_Clipboard-cut-copy-and-paste-with-JavaScript.html
注意:这仅适用于 IE(这对您的应用程序来说很好)。
我知道它无论如何都不是万无一失的,但是这里有一个代码示例可以帮助您入门:
<html>
<head>
<script type = "text/javascript">
var lastForm = null;
window.onload = function(){
var menu = document.getElementById("ContextMenu");
var cpy = document.getElementById("CopyBtn");
var pst = document.getElementById("PasteBtn");
document.body.onmouseup = function(){
if (event.button == 2)
{
menu.style.left = event.clientX + "px";
menu.style.top = event.clientY + "px";
menu.style.display = "block";
return true;
}
menu.style.display = "none";
};
cpy.onclick = function(){
copy = document.selection.createRange();
copy.execCommand("Copy");
return false;
};
pst.onclick = function(){
if (lastForm)
{
copy = lastForm.createTextRange();
copy.execCommand("Paste");
}
return false;
};
};
</script>
</head>
<body oncontextmenu = "return false;">
<div id = "ContextMenu" style = "display : none; background: #fff; border: 1px solid #aaa; position: absolute;
width : 75px;">
<a href = "#" id = "CopyBtn" style = "display: block; color : blue; text-decoration: none;">Copy</a>
<a href = "#" id = "PasteBtn" style = "display: block; color : blue; text-decoration: none;">Paste</a>
</div>
sadgjghdskjghksghkds
<input type = "text" onfocus = "lastForm = this;" />
</body>
</html>