2

Below is my code to "copy to clipboard" everything is workingfine with except its not working on safari browser... please help

<textarea id="mcq1" style="width:1px; height:1px; opacity:0; position:absolute;">
    <iframe src="http://s.rabblerapp.com/widget/widget.php?raw_uuid=de8c6880-9624-4b1d-8905-a3e2ab290660" style="width:100%;height:635px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0"></iframe>
</textarea>

<button class="rb_mcqbtn btn" data-clipboard-action="copy" data-clipboard-target="#mcq1" onclick="show_area('copied');">Copy Embed Code</button>

This is javascript i have use for this... https://zenorocha.github.io/clipboard.js

Zeno Rocha
  • 3,226
  • 1
  • 23
  • 27
varun tanwar
  • 23
  • 1
  • 1
  • 4
  • hi if i give a code to copy a text without any plugin will it work for you – Tanmay Dec 13 '15 at 18:01
  • It appears the [Safari 10](https://developer.apple.com/library/prerelease/content/releasenotes/General/WhatsNewInSafari/Articles/Safari_10_0.html) is now supporting `document.execCommand("copy")` so that clipboard.js should work in the newest Safari now. – jfriend00 Jun 24 '16 at 16:36

2 Answers2

3

I had a look at their site..

Look here: link

This library relies on both Selection and execCommand APIs. The second one is supported in the following browsers.

images here.....

Although copy/cut operations with execCommand aren't supported on Safari yet (including mobile), it gracefully degrades because Selection is supported.

Josh Murray
  • 619
  • 5
  • 18
1

I agree to review their docs and create a solution that works for you but this is what I came up with as a simple fallback. Allows you to not have to use a 3rd party tipsy library. I just toggle the target text.


    var CopytoClipboard = new Clipboard('.clipboard-copy');
    CopytoClipboard.on('success', function(e) {
      var $target = $(e.trigger);
      var oText = $target.html();
      $target.html("Copied!");
      setTimeout(function () {
        $target.html(oText);
      }, 800);
    });
    CopytoClipboard.on('error', function(e) {
      var $target = $(e.trigger);
       var oText = $target.html();
      $target.html("Press ⌘C to copy");
      setTimeout(function () {
        $target.html(oText);
      }, 3000);
    });

moladukes
  • 46
  • 4