"JavaScript 클립보드로 복사하기"의 두 판 사이의 차이

2번째 줄: 2번째 줄:
;JavaScript 클립보드로 복사하기
;JavaScript 클립보드로 복사하기
;자바스크립트 클립보드 복사
;자바스크립트 클립보드 복사
*자동으로 복사하는 것은 [[인터넷 익스플로러]]만 가능
* (예전 방식) 플래시 활용 [[ZeroClipboard]] 참고
*플래시를 활용하면 다른 브라우저도 가능 ([[ZeroClipboard]] 참고)


IE10 이상, Chrome, Opera, Firefox 모두 자동으로 복사가 가능합니다. ( Chrome 43+, Opera 29+ and IE 10+)
==예시 1: ==
* IE10 이상, Chrome, Opera, Firefox 가능<ref>Chrome 43+, Opera 29+, IE 10+</ref>
참고함수.
참고함수.
<source lang='html5'>
<source lang='html'>
function myFunction() {
<input id="myInput" value="Hello, World!">
<button onclick="copy_to_clipboard()">클립보드로 복사</button>
 
<script>
function copy_to_clipboard() {
   var copyText = document.getElementById("myInput");
   var copyText = document.getElementById("myInput");
   copyText.select();
   copyText.select();
   document.execCommand("Copy");
   document.execCommand("Copy");
  alert("Copied the text: " + copyText.value);
}
}
</script>
</source>
</source>



2017년 12월 13일 (수) 17:47 판

1 개요

JavaScript 클립보드로 복사하기
자바스크립트 클립보드 복사

2 예시 1:

  • IE10 이상, Chrome, Opera, Firefox 가능[1]

참고함수.

<input id="myInput" value="Hello, World!">
<button onclick="copy_to_clipboard()">클립보드로 복사</button>

<script>
function copy_to_clipboard() {
  var copyText = document.getElementById("myInput");
  copyText.select();
  document.execCommand("Copy");
}
</script>

3 예시 1: 자동복사

<script type="text/javaScript">
function copy_to_clipboard(str) {
  window.clipboardData.setData("Text", str);
  alert("복사되었습니다.");
}
</script>

<button onclick="copy_to_clipboard('Hello Jmnote');">복사</button>

4 예시 2: 자동 수동 혼합

<script type="text/javaScript">
function is_ie() {
  if(navigator.userAgent.toLowerCase().indexOf("chrome") != -1) return false;
  if(navigator.userAgent.toLowerCase().indexOf("msie") != -1) return true;
  if(navigator.userAgent.toLowerCase().indexOf("windows nt") != -1) return true;
  return false;
}
 
function copy_to_clipboard(str) {
  if( is_ie() ) {
    window.clipboardData.setData("Text", str);
    alert("복사되었습니다.");
    return;
  }
  prompt("Ctrl+C를 눌러 복사하세요.", str);
}
</script>
 
<button onclick="copy_to_clipboard('Hello Jmnote2');">복사</button>

5 같이 보기

6 참고

  1. Chrome 43+, Opera 29+, IE 10+
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}