Reputation: 21
I am faced with a little problem, I try to use clipboard.js, but it doesn't work even in my test. My html is as following, please tell me what I have done wrong.
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<meta name="description" content="test" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js"></script>
</head>
<body content="text/html">
<button class="btn" data-clipboard-demo="" data-clipboard-action="copy" data-clipboard-text="Just because you can doesn't mean you should — clipboard.js">Copy to clipboard</button>
</body>
</html>
Upvotes: 0
Views: 871
Reputation: 5926
You need to init clipboard js on your element. Add this to your page:
<script>new ClipboardJS('.btn')</script>
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<meta name="description" content="test" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js"></script>
</head>
<body content="text/html">
<button class="btn" data-clipboard-demo="" data-clipboard-action="copy" data-clipboard-text="Just because you can doesn't mean you should — clipboard.js">Copy to clipboard</button>
</body>
<script>new ClipboardJS('.btn');</script>
</html>
Upvotes: 2