// 버튼 클릭 했을 때
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');
}