Hari Om
Here is the html code to add "copy button" to your blog
<p>
<textarea class="js-copytextarea">
Sample Text to be copied</textarea><br />
</p>
<p>
<button class="js-textareacopybtn">Copy it</button>
</p>
<script>
var copyTextareaBtn = document.querySelector('.js-textareacopybtn');
copyTextareaBtn.addEventListener('click', function(event) {
var copyTextarea = document.querySelector('.js-copytextarea');
copyTextarea.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copying text command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}
});
</script>
Example
No comments:
Post a Comment