Skip to content

Instantly share code, notes, and snippets.

@gracefullight
Created December 21, 2016 09:06
Show Gist options
  • Save gracefullight/2b32beefafdfc8f6e1cc83f057ebae29 to your computer and use it in GitHub Desktop.
Save gracefullight/2b32beefafdfc8f6e1cc83f057ebae29 to your computer and use it in GitHub Desktop.
<script src="/bower_components/clipboard/dist/clipboard.min.js"></script>
<!-- 1. URL copy -->
<a href="#" id="btnCopyUrl" data-clipboard-action="copy" >url 복사</a>
<script>
$(function({
// 복사 버튼을 만들시 data-clipboard-text 안에 복사할 문구를 넣어준다
$('#btnCopyUrl').attr('data-clipboard-text', document.location.href);
// callback 설정
var clipboard = new Clipboard('#btnCopyUrl');
clipboard.on('success', function(e) {
alert('복사되었습니다');
});
clipboard.on('error', function(e) {
console.log(e);
});
});
</script>
<!-- 2. Text copy -->
<textarea id="textBody" cols="30" rows="5"></textarea>
<button type="button" id="btnCopyText" data-clipboard-action="copy" data-clipboard-target="#textBody">텍스트복사</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment