Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- MySQL
- java
- Effective Java
- log_bin
- Effective Java 3/e
- Spring Batch
- Chunk
- eslint
- Node
- migration
- mysql 5.5
- Webpack
- 퀵소트
- git
- update
- Express
- spring
- npm
- regex
- upgrade
- REACT
- nodejs
- Regular expression
- REACTJS
- current_date
- expire_logs_days
- 정규표현식
- spring cloud
- log4j2
- JavaScript
Archives
- Today
- Total
내 세상
[React] Copy to Clipboard 본문
728x90
// 흐음 1.
if (navigator.clipboard) {
// (IE는 사용 못하고, 크롬은 66버전 이상일때 사용 가능합니다.)
navigator.clipboard
.writeText(text)
.then(() => {
alert("클립보드에 복사되었습니다.");
})
.catch(() => {
alert("복사를 다시 시도해주세요.");
});
} else {
// 흐름 2.
if (!document.queryCommandSupported("copy")) {
return alert("복사하기가 지원되지 않는 브라우저입니다.");
}
// 흐름 3.
const textarea = document.createElement("textarea");
textarea.value = text;
textarea.style.top = 0;
textarea.style.left = 0;
textarea.style.position = "fixed";
// 흐름 4.
document.body.appendChild(textarea);
// focus() -> 사파리 브라우저 서포팅
textarea.focus();
// select() -> 사용자가 입력한 내용을 영역을 설정할 때 필요
textarea.select();
// 흐름 5.
document.execCommand("copy");
// 흐름 6.
document.body.removeChild(textarea);
alert("클립보드에 복사되dd었습니다.");
}
728x90
'Technical > React' 카테고리의 다른 글
[React] node-sass error (0) | 2023.01.04 |
---|---|
[React] MUI ClickAwayListener (0) | 2022.12.23 |
[React] React Project 초기설정 참고 (0) | 2022.11.22 |
[React] Regex/정규표현식/Regular Expression (0) | 2021.12.10 |
[React] react-contextmenu에서 react-contexify로 변경한 이유 (0) | 2021.04.21 |