티스토리 뷰
반응형
Copy & Paste 시에 텍스트만 가져오도록 처리 onpaste 이벤트에 걸면된다.
const getTextByPasteClipboard = (e) => {
e.preventDefault();
let text;
const clp = (e.originalEvent || e).clipboardData;
if (clp === undefined || clp === null) {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
text = window.clipboardData.getData('text') || '';
if (text !== '') {
text = text.replace(/<[^>]*>/g, '');
if (window.getSelection) {
const newNode = document.createElement('span');
newNode.innerHTML = text;
window.getSelection().getRangeAt(0).insertNode(newNode);
} else {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
document.selection.createRange().pasteHTML(text);
}
}
} else {
text = clp.getData('text/plain') || '';
if (text) {
text = text.replace(/<[^>]*>/g, '');
document.execCommand('insertText', false, text);
}
}
};반응형
'웹프로그래밍 > Javascript' 카테고리의 다른 글
| window.open 새로운 윈도우 창에 post 로 보내기 (0) | 2022.05.31 |
|---|---|
| validate JSON (JSON 여부 검사) (0) | 2020.07.08 |
| get Image width and height (0) | 2020.07.08 |
| moment.js (날짜관련 작업을 위한 자바스크립트 라이브러리) (0) | 2020.02.11 |
| [Javascript] 페이지를 떠날 때 경고창 띄우기 (0) | 2017.05.19 |
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 신혼부부
- 연말정산
- 아파트매매
- 안과
- 공제
- 재테크
- 내집마련
- 대출
- remove
- 카뱅
- 앱테크
- 카카오뱅크
- 우회
- 출산
- etf
- 주담대
- 금융
- 지도
- ubuntu
- 해외주식
- 안드로이드
- 적금
- 고금리
- 부동산
- 혜택
- 정부
- 투자
- 세금
- 2026
- php
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
글 보관함