Search This Blog

How to show code on blogger / blogspot with a copy snippet button


To show copy code snippet button for any code. Do the following steps:

  1. Go to HTML View of blog post's editor.
  2. Paste the below lines inside HTML editor & replace the Your Actual Code with the desired code.
<textarea style="border-style: solid; border-width: 1px 1px 1px 20px; border-color: #4072a1; width: 100%; height: 321px; line-height: 16px; resize: none;" id="html1" readonly> Your Actual Code</textarea><div style="font-size:13px; font-family: comic sans ms; color: blue;"><button onclick="copyThis1()">Copy code snippet</button></div>
<script>
function copyThis1() {
  var copyText = document.getElementById("html1");
  copyText.select();
  copyText.setSelectionRange(0, 99999)
  document.execCommand("copy");
  alert("Code snippet copied to clipboard");
}
</script>



No comments:

Post a Comment