Skip to content

Instantly share code, notes, and snippets.

@JohnnyMa
Created October 9, 2015 06:41
Show Gist options
  • Save JohnnyMa/6900f96a9e17253a0747 to your computer and use it in GitHub Desktop.
Save JohnnyMa/6900f96a9e17253a0747 to your computer and use it in GitHub Desktop.
A modern approach to copy text to clipboard, pure js.
<!doctype html>
<html>
<head>
<title>test copy</title>
<script src="clipboard.min.js"></script>
</head>
<body>
<!-- Target -->
<input id="foo" value="test text... text">
<!-- Trigger -->
<button class="btn" data-clipboard-target="#foo">
<img src="assets/clippy.svg" alt="Copy to clipboard">
</button>
<!-- repo: https://github.com/zenorocha/clipboard.js -->
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment