最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Copy to Clipboard is Not Working in safari - Stack Overflow

programmeradmin0浏览0评论

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=".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... .js

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./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

Share Improve this question edited Dec 26, 2015 at 18:55 Zeno Rocha 3,5861 gold badge25 silver badges27 bronze badges asked Dec 13, 2015 at 17:53 varun tanwarvarun tanwar 331 gold badge1 silver badge4 bronze badges 2
  • hi if i give a code to copy a text without any plugin will it work for you – Tanmay Commented Dec 13, 2015 at 18:01
  • It appears the Safari 10 is now supporting document.execCommand("copy") so that clipboard.js should work in the newest Safari now. – jfriend00 Commented Jun 24, 2016 at 16:36
Add a ment  | 

2 Answers 2

Reset to default 4

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.

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

发布评论

评论列表(0)

  1. 暂无评论