I
I
Igor2016-09-10 19:25:50
JavaScript
Igor, 2016-09-10 19:25:50

How to copy text to clipboard from popup.js chrome extension clipboard?

https://jsbin.com/mayenevubi/edit?html , js tried
this way but throws Discontiguous selection is not supported.
here is the manifest

"permissions": [
    "webNavigation",
    "notifications",
    "tabs",
      "storage",
    "clipboardRead",
    "clipboardWrite"
  ],

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2016-09-12
@IgorBee

<textarea class="js-copytextarea">Hello I'm so11111me text</textarea>

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');
  }
});

on click launch this function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question