JS Implements Method of Getting Clipboard Content

  • 2021-06-29 09:51:25
  • OfStack

This article provides an example of how JS implements getting clipboard content.Share it for your reference, as follows:

The code for JS to get clipboard content is described here:


<Script Language="JavaScript">
var content = clipboardData.getData("Text");
if (content!=null) {
  document.write("<center><font size=5 color=red>WARNING, TEXT RETRIEVED:</font> (see below)<br><br><span style='background-color: #FFFF00'>");
  document.write(content);
  document.write("</span>");}
else {
  document.write('<center>No text found in clipboard. This is a good thing!<br><br>Works with Internet Explorer and Netscape.');
}
</Script>


var o=pos.parentElement().parentNode;
var txt=window.clipboardData.getData("Text");
$('#tempForClip').val(txt);
var temp=$('#tempForClip').val();
window.clipboardData.setData("Text",temp);

More readers interested in JavaScript-related content can view this site's topics: JavaScript Switching Special Effects and Techniques Summary, JavaScript Find Algorithmic Techniques Summary, JavaScript Animation Special Effects and Techniques Summary, JavaScript Errors and Debugging Techniques Summary, JavaScript Data Structure and Algorithmic Techniques Summary, etc.Summary of JavaScript Traversal Algorithms and Techniques and Summary of JavaScript Mathematical Operation Usage

I hope that the description in this paper will be helpful to everyone's JavaScript program design.


Related articles: