Skip to content

Kavehkakai/copy_url_on_button_click

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

//How to copy URL on button click with javascript


<textarea id="url" rows="1" cols="30" style="display:none"></textarea>
<script> function CopyUrl() { const url = window.location.href; navigator.clipboard.writeText(url); alert("URL copied to clipboard!"); }

function HideUrl() { document.getElementById("url").style.display = "none"; } </script>```

The navigator.clipboard.writeText() method is used to write text to the clipboard. The url parameter is used to specify the text that is being copied.

I hope this code works for you.

About

How to copy URL on button click

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published