Javascript copy and paste with the use of clipboardData

  • 2020-03-30 04:09:52
  • OfStack

Window.clipboarddata can be used to copy and paste, its getData method can be used to read data, and setData method can be used to setData


 <script language="javascript"> 
function readTxt() 
{ 
alert(window.clipboardData.getData("text")); 
} 
function setTxt() 
{ 
var t=document.getElementById("txt"); 
t.select(); 
window.clipboardData.setData('text',t.createTextRange().text); 
} 
</script> 
<input name="txt" value=" test "> 
<input type="button" value=" copy " onclick="setTxt()"> 
<input type="button" value=" read " onclick="readTxt()">

Related articles: