1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | // 버튼 클릭 했을 때 function onClick_clipboard(){ /* Get the text field */ var copyText = document.getElementById( "clipboard" ); var isIOS = (UserAgent.match(/i(Phone|Pod)/i) != null ) true : false ; if (isIOS){ // ios 일때 iosCopyToClipboard(copyText); } else { // ios가 아닐때 copyToClipboard(copyText); } /* Alert the copied text */ alert( "copy 되었습니다." ); return false ; } // ios가 아닐 때 function copyToClipboard(copyText){ /* Select the text field */ copyText.select(); /* Copy the text inside the text field */ document.execCommand( "copy" ); } // ios 일때 function iosCopyToClipboard(el) { var oldContentEditable = el.contentEditable, oldReadOnly = el.readOnly, range = document.createRange(); el.contentEditable = true ; el.readOnly = false ; range.selectNodeContents(el); var s = window.getSelection(); s.removeAllRanges(); s.addRange(range); // A big number, to cover anything that could be inside the element. el.setSelectionRange(0, 999999); el.contentEditable = oldContentEditable; el.readOnly = oldReadOnly; document.execCommand( 'copy' ); } |
'프로그래밍 > javascript' 카테고리의 다른 글
[javascript] 현재 페이지 이름 가져오기 (0) | 2016.11.17 |
---|---|
[javascript] 키보드 숫자만 입력받게 하기 (0) | 2016.11.17 |
[javascript] 정규식 유효성 검사 (0) | 2016.11.17 |
[javascript] 3자리 마다 쉼표 찍기 (0) | 2016.11.17 |
[javascript] 배열 오름차순 내림차순 정렬 (0) | 2016.11.17 |