Create Dream Website

How to create a “Copy Link” button (Elementor Tutorial)

Copy link Button , copy link button in wordpress website

Add id "copyURL" to button

JavaScript
<script>
const copyBtn = document.getElementById('copyURL');
 /*!
 * © This code was written by Aditya Yadav.
 * For more information, visit my Youtube channel:https://www.youtube.com/@CreateDreamWebsite
 */
copyBtn.addEventListener('click', () => {
  const url = window.location.href;
  navigator.clipboard.writeText(url).then(() => {
    alert('URL copied successfully!');
  }).catch(() => {
    alert('Error copying URL to clipboard');
  });
});
</script>


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top