Skip to content

Instantly share code, notes, and snippets.

@romeoh
Created April 10, 2013 01:19
Show Gist options
  • Save romeoh/5350983 to your computer and use it in GitHub Desktop.
Save romeoh/5350983 to your computer and use it in GitHub Desktop.
clipboard
<!DOCTYPE HTML>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, target-densitydpi=medium-dpi">
<title>sample</title>
<style type="text/css">
input {width:300px}
/* 아래는 input요소를 제외하고 모든 요소에 팝업뜨지 않게 하는 css소스 *
*:not(input) { -webkit-user-select:none; }
*/
</style>
</head>
<body>
<input type="text" id="inpCopy" data-value="안녕하세요. 완전 다른 데이터 넣어보겠습니다." value="이거 copy해보세요.">
<input type="text" id="inpPaste" value="" placeholder="여기에 붙여넣기">
<script type="text/javascript">
// 복사 이벤트
window.addEventListener('copy', function (e){
e.preventDefault();
e.clipboardData.setData('text/plain', document.querySelector('#inpCopy').dataset.value);
}, false)
// 잘라내기 이벤트
window.addEventListener('cut', function (e){
e.preventDefault();
e.clipboardData.setData('text/plain', document.querySelector('#inpCopy').dataset.value);
}, false)
// 붙여넣기 이벤트
window.addEventListener('paste', function (e){
console.log(e.clipboardData.getData('text/plain'));
}, false)
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment