我把代码贴出来给大家看看? copy,cut是没有问题,现在的问题就是paste?老是有问题,请大家多关照! <html> <head> <style> #ie5menu { position:absolute; width:30px; border:1px solid green; background-color:menu; font-family:Verdana; font-size:9pt; line-height:15px; cursor:hand; visibility:hidden; } .menuitems { padding-left:5px; padding-right:5px; width:65; height: 25 } </style> <script language="JavaScript"> //set this variable to 1 if you wish the URLs of //the highlighted menu to be displayed in the status bar var display_url=0 var oTempRange=null; function showmenuie5() {var rightedge=document.body.clientWidth-event.clientX ; var bottomedge=document.body.clientHeight-event.clientY ; if(rightedge<ie5menu.offsetWidth){ ie5menu.style.left=document.body.scrollLeft+event.clientX-ie5menu.offsetWidth ; }else{ ie5menu.style.left=document.body.scrollLeft+event.clientX ; } if(bottomedge<ie5menu.offsetHeight){ ie5menu.style.top=document.body.scrollTop+event.clientY-ie5menu.offsetHeight ; }else{ ie5menu.style.top=document.body.scrollTop+event.clientY ; ie5menu.style.visibility="visible" ; return false ; } }function hidemenuie5(){ if(document.selection.type=="Text"){
oTempRange=document.selection.createRange();
} ie5menu.style.visibility="hidden"
}function highlightie5() { if(event.srcElement.className=="menuitems") { event.srcElement.style.cursor="hand" event.srcElement.style.backgroundColor="highlight" event.srcElement.style.color="red" }else { event.srcElement.style.cursor="default" } } function lowlightie5() { if (event.srcElement.className=="menuitems"){ event.srcElement.style.backgroundColor="" event.srcElement.style.color="black" document.firstChild.window.status='' }}function copyText(){ var result = oTempRange.text;
var bResult = window.clipboardData.setData("Text",result);
} function copyHtml(){ var result = oTempRange.htmlText;
var bResult = window.clipboardData.setData("Text",result);
}
function paste(){
oTempRange.execCommand("paste");
var head = document.firstChild.firstChild.outerHTML; var hm = document.body.outerHTML; hm =hm.replace(/</i,"<"); hm =hm.replace(/>/i,">"); hm = "<html>"+head+hm+"</html>"; document.removeChild(document.firstChild); document.write(hm); }
function cutText(){ var result = oTempRange.text; window.clipboardData.setData("Text",""); oTempRange.execCommand("paste"); var bResult = window.clipboardData.setData("Text",result);
}
function cutHtml(){ var result = oTempRange.htmlText; window.clipboardData.setData("Text",""); oTempRange.execCommand("paste");
var bResult = window.clipboardData.setData("Text",result);
<HTML>
<HEAD>
<TITLE> Q2413389 </TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<META NAME="Generator" CONTENT="Microsoft Notepad">
<META NAME="Author" CONTENT="Topmonkey">
<META NAME="Keywords" CONTENT="http://expert.csdn.net/Expert/topic/2413/2413389.xml?temp=.4325983">
<META NAME="Description" CONTENT="Re: Q2413389"></HEAD><BODY bgcolor="#FFFFFF" leftmargin="0" topmargin="0">
<Table Width="50" Align="Center" Border="1">
<tr>
<td id=a> </td>
</tr>
</Table>
<Script Language="JavaScript">
<!--
var x,y;
document.onmousemove = get_xy;
function get_xy(){
x=event.x;
y=event.y;
a.innerHTML="x="+x+"<br>y="+y;
}
//-->
</Script>
</BODY>
</HTML>
var r=document.selection.createRange();
r.execCommand('Paste');
捕获按下ctrl+c按键事件然后自动生成一个层,再把内容拷贝到里边
event.srcElement.getBoundingClientRect().top
event.srcElement.getBoundingClientRect().left剪贴班内容
window.clipboardData.getData("Text")
copy,cut是没有问题,现在的问题就是paste?老是有问题,请大家多关照!
<html>
<head>
<style>
#ie5menu
{
position:absolute;
width:30px;
border:1px solid green;
background-color:menu;
font-family:Verdana;
font-size:9pt;
line-height:15px;
cursor:hand;
visibility:hidden;
} .menuitems
{
padding-left:5px;
padding-right:5px;
width:65;
height: 25
} </style>
<script language="JavaScript">
//set this variable to 1 if you wish the URLs of
//the highlighted menu to be displayed in the status bar
var display_url=0
var oTempRange=null;
function showmenuie5()
{var rightedge=document.body.clientWidth-event.clientX ;
var bottomedge=document.body.clientHeight-event.clientY ;
if(rightedge<ie5menu.offsetWidth){
ie5menu.style.left=document.body.scrollLeft+event.clientX-ie5menu.offsetWidth ;
}else{
ie5menu.style.left=document.body.scrollLeft+event.clientX ;
}
if(bottomedge<ie5menu.offsetHeight){
ie5menu.style.top=document.body.scrollTop+event.clientY-ie5menu.offsetHeight ;
}else{
ie5menu.style.top=document.body.scrollTop+event.clientY ;
ie5menu.style.visibility="visible" ;
return false ;
}
}function hidemenuie5(){
if(document.selection.type=="Text"){
oTempRange=document.selection.createRange();
} ie5menu.style.visibility="hidden"
}function highlightie5()
{
if(event.srcElement.className=="menuitems")
{
event.srcElement.style.cursor="hand"
event.srcElement.style.backgroundColor="highlight"
event.srcElement.style.color="red"
}else {
event.srcElement.style.cursor="default"
}
} function lowlightie5()
{
if (event.srcElement.className=="menuitems"){
event.srcElement.style.backgroundColor=""
event.srcElement.style.color="black"
document.firstChild.window.status=''
}}function copyText(){ var result = oTempRange.text;
var bResult = window.clipboardData.setData("Text",result);
}
function copyHtml(){ var result = oTempRange.htmlText;
var bResult = window.clipboardData.setData("Text",result);
}
function paste(){
oTempRange.execCommand("paste");
var head = document.firstChild.firstChild.outerHTML;
var hm = document.body.outerHTML;
hm =hm.replace(/</i,"<");
hm =hm.replace(/>/i,">");
hm = "<html>"+head+hm+"</html>";
document.removeChild(document.firstChild);
document.write(hm);
}
function cutText(){
var result = oTempRange.text;
window.clipboardData.setData("Text","");
oTempRange.execCommand("paste"); var bResult = window.clipboardData.setData("Text",result);
}
function cutHtml(){
var result = oTempRange.htmlText;
window.clipboardData.setData("Text","");
oTempRange.execCommand("paste");
var bResult = window.clipboardData.setData("Text",result);
}
</script>
</head><body><div id="ie5menu"><div class="menuitems" onClick="copyText()" >Copy(T)</div>
<div class="menuitems" onClick="copyHtml()" >Copy(H)</div>
<HR align=center width="65" size="1">
<div class="menuitems" onClick="cutText()" >Cut(T)</div>
<div class="menuitems" onClick="cutHtml()" >Cut(H)</div>
<HR align=center width="65" size="1">
<div class="menuitems" onClick="paste()" >Paste</div></div><p id="p">
点击右键打开菜单<br>
<form>
<input type="text" name=txtSearch value="dddd">
<input type=button value=Copy2Clip onclick='javascript: var textRange=txtSearch.createTextRange(); textRange.execCommand("Copy")'>
<input type=button value=PastefromClip onclick='javascript: var textRange=txtSearch.createTextRange(); textRange.execCommand("Paste")'>
</form>
</body> <script language="javascript">
document.oncontextmenu=showmenuie5
if (document.all && window.print) document.body.onclick=hidemenuie5;
</script>
</html>