브라우져에서 값을 복사하는 기능이 내가 운영하는 사이트에서 많이 필요한데,
현재 우리 사이트를 사용하는 고객들이 대부분 IE 여서 문제는 없었지만,
다른 브라우져는 사용하는 고객들이 점점 늘어나면서 크롬 기반 브라우져에서도 선택된 값을 복사해야 하는 기능 요구가 있어서 찾아보니, 위의 command가 있었다..ㅠㅠ
이래서 계속 공부를 해야하는건뎅..쩝..
아래의 내용은 https://www.w3schools.com/jsref/met_document_execcommand.asp 여기를 참고했다.
Syntax : document.execCommand(command, showUI, value)
1. command 는 copy 이외에도 다양하게 많다.
"backColor","bold","createLink","copy","cut","defaultParagraphSeparator","delete","fontName","fontSize","foreColor"
,"formatBlock","forwardDelete","insertHorizontalRule","insertHTML","insertImage","insertLineBreak","insertOrderedList"
,"insertParagraph","insertText","insertUnorderedList","justifyCenter","justifyFull","justifyLeft","justifyRight","outdent"
,"paste","redo","selectAll","strikethrough","styleWithCss","subscript","superscript","undo","unlink","useCSS"
2. showUI : A Boolean, specifies if the UI should be shown or not
3. value : Some commands need a value to be completed
4. Return Value: A Boolean, false if the command is not supported, otherwise true
5. 지원 브라우져 : Chrome, IE(9.0), Firefox(41.0), Safari(20.0), Opera (29.0)
6. 사용 예 :
var copyobj = document.getElementById("p_copy");
copyobj.select();
var result = document.execCommand("copy");
if (result) alert('복사완료');