1

Can you please guide me on how to fix following issue, or suggest another option for copying to the clipboard?

function click_to_copy_password(containerid) {
    if (document.selection) {
        var range = document.body.createTextRange();
        range.moveToElementText(document.getElementById(containerid));
        range.select();

    } else if (window.getSelection) {
        var range = document.createRange();
        range.selectNode(document.getElementById(containerid));
        window.getSelection().removeAllRanges();
        window.getSelection().addRange(range);
    }

    document.execCommand('copy');
}

It's working fine in Chrome, Firefox & IE, but it does not work in Safari.

Frank Tan
  • 3,479
  • 1
  • 16
  • 29
Jaydip Satvara
  • 138
  • 1
  • 14
  • Hello. Welcome to Stack Overflow. Please have a look around and take the [tour], and read through the [help center]. You can also read about [ask] a good question. – Sampada Apr 22 '16 at 06:26
  • Some workarounds are suggested in [How do I copy to the clipboard in JavaScript?](http://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript) – Frank Tan Sep 09 '16 at 14:08

1 Answers1

4

At this moment, the execCommand('copy') API is not supported on Safari but this will change in Safari 10: https://developer.apple.com/library/archive/releasenotes/General/WhatsNewInSafari/Articles/Safari_10_0.html

Cœur
  • 32,421
  • 21
  • 173
  • 232
Zeno Rocha
  • 2,757
  • 1
  • 20
  • 27