JS Simple Realization Method of Click Copy Link

  • 2021-07-07 06:22:52
  • OfStack

In this paper, an example is given to describe the simple method of replication link in JS. Share it for your reference, as follows:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title> Click the Copy link </title>
</head>
<body>
<input type="text" size="30" id="url" value="https://www.ofstack.com/">
<input type="button" value=" Copy link 1" onClick="copyUrl()">
<script type="text/javascript">
function copyUrl(){
 var url = document.getElementById("url").value;
 window.clipboardData.setData("Text",url);
 alert(" Copy link successful! ");
}
</script>
<input type="button" value=" Copy link 2" onClick="url.select();document.execCommand('Copy')">
<br/><br/>
 Script House provides two simple ways to copy links, and I believe there are always 1 The model suits you ~O( STH _ STH )O~
</body>
</html>

More readers interested in JavaScript can check the topics of this site: "Summary of json Operation Skills in JavaScript", "Summary of JavaScript Switching Special Effects and Skills", "Summary of JavaScript Search Algorithm Skills", "Summary of JavaScript Animation Special Effects and Skills", "Summary of JavaScript Error and Debugging Skills", "Summary of JavaScript Data Structure and Algorithm Skills", "Summary of JavaScript Traversal Algorithm and Skills" and "Summary of JavaScript Mathematical Operation Usage"

I hope this article is helpful to everyone's JavaScript programming.


Related articles: