h5 micro-channel browser copy and paste solution --ios compatibility issues (clipboard.js plug-in)

Some time ago doing micro letter h5 when he met the ios compatible plug-ins using clipboard.js perfect solution

Download: Download: https://github.com/zenorocha/clipboard.js

cnd introduced js: https://cdn.staticfile.org/clipboard.js/1.5.15/clipboard.min.js

html part:

< Div ID = "foo" > content needs to be pasted </ div >  
<-! Copy button -> 
< A class = "copyBtn"   the href = "JavaScript:"   Data-Clipboard-Action = "Copy"   DATA- target-Clipboard = "# foo" > </ A >

js part:

 var clipboard = new Clipboard('.copyBtn').on('success', function(e) {
        var e = e || window.event;
        console.log('复制成功!!!');
    }).on('error', function(e) {});

 

complete

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>iOS复制兼容</title>
</head>
<body>
    <div id="foo">需要被粘贴的内容</div> 
    <!-- 复制按钮 -->
    <a class="copyBtn"  href="javascript:"  data-clipboard-action="copy"  data-clipboard-target="#foo"></a>
  <script type="text/javascript" src="https://cdn.staticfile.org/clipboard.js/1.5.15/clipboard.min.js"></script>
  <script>
    window.onload = function(){
      var clipboard = new Clipboard('.copyBtn').on('success', function(e) {
        var e = e || window.event;
        console.log('复制成功!!!');
    }).on('error', function(e) {});
  }
  </script>
</body>
</html>

 

Guess you like

Origin www.cnblogs.com/imMeya/p/11347641.html