I
I
it_pear_yurec2018-02-28 19:04:35
css
it_pear_yurec, 2018-02-28 19:04:35

How to make a similar input with a button?

How to make a similar input with a button so that it has a link and can be copied by clicking on the button?
css styles if not needed, only the principle of operation)
5a96d31161334703297189.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasyl Vandych, 2018-02-28
@it_pear_yurec

https://developer.mozilla.org/en-US/docs/Web/API/D...
here is the function.

var copyTextareaBtn = document.querySelector('.js-textareacopybtn');

copyTextareaBtn.addEventListener('click', function(event) {
  var copyTextarea = document.querySelector('.js-copytextarea');
  copyTextarea.select();

  try {
    var successful = document.execCommand('copy');
    var msg = successful ? 'successful' : 'unsuccessful';
    console.log('Copying text command was ' + msg);
  } catch (err) {
    console.log('Oops, unable to copy');
  }
});
<p>
  <button class="js-textareacopybtn" style="vertical-align:top;">Copy Textarea</button>
  <textarea class="js-copytextarea">Hello I'm some text</textarea>
</p>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question