DataTable을 사용하면서 조회 한 내용을 클립보드에 복사하는법 입니다.
const table = document.getElementById("testTable");
const rows = table.tBodies[0].rows;
const clipboardData = [];
for (let i = 0; i < rows.length; i++) {
const row = rows[i];
const rowData = [];
for (let j = 0; j < row.cells.length; j++) {
rowData.push(row.cells[j].textContent);
}
clipboardData.push(rowData.join("\t"));
}
const clipboardText = clipboardData.join("\n");
const tempTextArea = document.createElement("textarea");
tempTextArea.value = clipboardText;
document.body.appendChild(tempTextArea);
tempTextArea.select();
document.execCommand("copy");
document.body.removeChild(tempTextArea);
'개발자 > JavaScript&jQuery' 카테고리의 다른 글
| 유튜브 iframe 클릭 시 유튜브 바로가기 (0) | 2025.05.29 |
|---|---|
| [parsley] 파슬리로 유효성 체크 방법 (0) | 2024.07.05 |
| [카카오 웹] 카카오 웹에서 외부 URL 호출 방법 (0) | 2024.06.26 |
| [iframe] PDF 화면 출력 시 상단 툴바 없애는 방법 (0) | 2024.06.19 |
| [JavaScript] window.open 자동으로 닫히게 하는 방법 (0) | 2024.06.13 |