复制到剪贴板在 safari 中不起作用

Copy to Clipboard is Not Working in safari

下面是我的代码 "copy to clipboard" 除了在 safari 浏览器上不工作外一切正常...请帮助

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

这是javascript我用过这个... https://zenorocha.github.io/clipboard.js

我看过他们的网站..

看这里: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.

我同意查看他们的文档并创建适合您的解决方案,但这是我想出的一个简单的后备方案。允许您不必使用第 3 方醉意库。我只是切换目标文本。


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