Logo

dev-resources.site

for different kinds of informations.

How to create COPY TO CLIPBOARD BUTTON for url of webpage

Published at
12/24/2023
Categories
css
javascript
html
immodded
Author
immodded
Categories
4 categories in total
css
open
javascript
open
html
open
immodded
open
How to create COPY TO CLIPBOARD BUTTON for url of webpage
<button onclick="copyURL()">Copy</button>

<script>
  function copyURL() {
    var currentURL = window.location.href;
    var tempInput = document.createElement("input");
    tempInput.value = currentURL;
    document.body.appendChild(tempInput);
    tempInput.select();
    tempInput.setSelectionRange(0, 99999); 
    document.execCommand("copy");
    document.body.removeChild(tempInput);
    alert("Copied!")
  }
</script>

Featured ones: