-1

Here is my HTML code:

  <input id="text" type="text" name="text">
    <input type="button" name="page1" onclick="javascript:window.open('http://example.com/' + this.name + '/' + document.getElementById('text').value)">

If you put any text in the field it and click on the button it will redirect to http://example.com/page1/anytext I'm trying to make this button to be able to redirect to the URL and also copy it to clipboard. So if any visitor put anytext on the field it will copy the url http://example.com/page1/anytext and also redirect to the URL.

SudoGuy
  • 135
  • 1
  • 1
  • 7
  • 2
    Possible duplicate of [How do I copy to the clipboard in JavaScript?](https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript) – Ali Nov 25 '17 at 14:27

1 Answers1

0

As follows:

function myCopyFunction() {
  var copyText = document.getElementById("page1");
  copyText.select();
  document.execCommand("Copy");
  alert("Copied the text: " + copyText.value);
}
Carlos E
  • 1,691
  • 1
  • 23
  • 31