Skip to content

Instantly share code, notes, and snippets.

@gabrieljmj
Last active October 28, 2015 01:59
Show Gist options
  • Save gabrieljmj/e9034f3dc5bf1328286c to your computer and use it in GitHub Desktop.
Save gabrieljmj/e9034f3dc5bf1328286c to your computer and use it in GitHub Desktop.
Copy to clipboard without clipboard.js
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<textarea>:) this is a fuckin' text</textarea>
<button>Copy</button>
<script src="main.js"></script>
</body>
</html>
document.querySelector('button').onclick = function () {
document.querySelector('textarea').select();
document.execCommand('copy');
alert('copied');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment