I am trying to copy the current page URL in the text area on button click. Somehow I have tried but is not working. http://www.w3schools.com/code/tryit.asp?filename=FAF25LWI
No need to create new textarea. try to get existing textarea by giving some id ('url').
textarea
id
Here is the working example
function Copy() { var Url = document.getElementById("url"); Url.innerHTML = window.location.href; console.log(Url.innerHTML) Url.select(); document.execCommand("copy"); }
Paste: