html - Add copy button in Javascript -
i'm trying add button copy text textarea using zeroclipboard, however, when click button, nothing happens , when paste nothing has been added clipboard.
var clip = new zeroclipboard( document.getelementbyid("btn4"), { moviepath: "https://rawgit.com/zeroclipboard/zeroclipboard/master/dist/zeroclipboard.swf" } ); clip.on( "load", function(client) { // alert( "movie loaded" ); client.on( "complete", function(client, args) { // `this` element clicked this.style.display = "none"; } ); } );
<div id ="right" style = "float:left; width: 10%; margin-left:185px; margin-top:35px"> <button id="btn4" data-clipboard-target="block2" name ="btn4" type="button" class="btn btn-success"><i class="icon-white icon-file"></i> copy</button> <script src="https://rawgit.com/zeroclipboard/zeroclipboard/master/dist/zeroclipboard.js"></script> </div> <textarea id="block2" name="block2" style="font-family:rockwell; background-color:#d1d1d1"></textarea>
try:
<script language="javascript"> var copytextareabtn = document.queryselector('.btn4'); copytextareabtn.addeventlistener('click', function(event) { var copytextarea = document.queryselector('.block2'); copytextarea.select(); try { var successful = document.execcommand('copy'); var msg = successful ? 'successful' : 'unsuccessful'; console.log('copying text command ' + msg); } catch (err) { console.log('oops, unable copy'); } }); </script>
Comments
Post a Comment