2

I have tried the following in the fetch success callback, but it fails and returns false. This issue occurs in Edge browser.

document.execCommand('copy')

HTML Code:

<div id="toCopy">
    new value 12345
    <br /><br />
    <a href="#">Link</a>
</div>

Backbone JS code:

toCopy = Backbone.Model.extend({});
toCopy.fetch({
  "id": "xxx",
}).done(function(resp) {

  if (window.getSelection) {
    var range = document.createRange();
    range.selectNodeContents(document.getElementById("toCopy"));
    window.getSelection().removeAllRanges();
    window.getSelection().addRange(range);
  }
  document.execCommand("copy");
});
Emile Bergeron
  • 14,368
  • 4
  • 66
  • 111
Sethu Bala
  • 465
  • 3
  • 16
  • 1
    Possible duplicate of [document.execCommand copy command does not work or other solution?](http://stackoverflow.com/questions/14253634/document-execcommand-copy-command-does-not-work-or-other-solution) – T J Apr 11 '17 at 09:40
  • Perhaps, you could do something which I mentioned here: [SOLVED: document execCommand copy not working with AJAX](http://stackoverflow.com/questions/43380921/not-able-to-copy-a-link-directly-when-i-am-using-ajax/43381458#43381458) – Nishanth Matha Apr 13 '17 at 07:55
  • Possible duplicate of [document execCommand copy not working with AJAX](https://stackoverflow.com/questions/43380921/document-execcommand-copy-not-working-with-ajax) – Paul Sweatte Aug 25 '17 at 02:04

0 Answers0