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');
}
Posted by august5pm
,