clipboard-interaction

prerequisites

for browser

<script src="node_modules/clipboard-interaction/distrib/clipboard-interaction.min.js"></script>

Methods

copy

copy(text, onsuccess, onerror)

texttext to copy to clipboard

onsuccessfunction called when text copied

onerrorfunction called when error

<input id="source" type="text" placeholder="write something here" /> <button onclick="copy()">Copy to clipboard</button> <input id="target" type="text" placeholder="Ctrl+V to paste from clipboard" /> <script> function copy() { var source = document.getElementById("source"); var target = document.getElementById("target"); Clipboard.copy(source.value, function() { target.value = ""; target.focus(); alert("copied !"); }, function(err, msg) { alert(err.message); }); } </script>