1. document.execCommand("copy");
2. ๐ ์ฐธ๊ณ
์๋ฐ์คํฌ๋ฆฝํธ๋ฅผ ์ด์ฉํ์ฌ ๋ฒํผ ํด๋ฆญ์
ํ์ฌ ํ์ด์ง์ URL์ ํด๋ฆฝ๋ณด๋์ ๋ณต์ฌํ๋ ๊ธฐ๋ฅ์ ์ถ๊ฐํ๊ณ ์ถ์๋ค.
function clipBoard(){
let dummy = document.createElement("input");
const url = location.href;
document.body.appendChild(dummy);
dummy.value = url;
dummy.select();
document.execCommand("copy");
alert("URL์ ํด๋ฆฝ๋ณด๋์ ๋ณต์ฌํ์ต๋๋ค.");
document.body.removeChild(dummy);
}
html
ํจ์ ์คํ์ ์์๋ก URL์ ๋ด๋ input์ ์์ฑํ๊ณ ๋ณต์ฌ ํ ์ญ์ ํ๋ค.
1. document.execCommand("copy");
ํด๋ฆฝ๋ณด๋ ๋ณต์ฌ์ ํต์ฌ! ํด๋ฆฝ๋ณด๋์ ํ์ฌ ์ ํ ์์ญ์ ๋ด์ฉ์ ๋ณต์ฌํ๋ค.


ํด๋ฆญํ ํ์ ์ ๋ซ๊ณ ๋ฉ๋ชจ์ฅ์ ๋ถ์ฌ๋ฃ๊ธฐ ํ์ ๋ URL์ด ์ ๋ณต์ฌ๋ ๊ฒ ํ์ธ.
2. ๐ ์ฐธ๊ณ
https://developer.mozilla.org/ko/docs/Web/API/Document/execCommand
Document.execCommand() - Web API | MDN
HTML ๋ฌธ์๊ฐ designMode๋ก ์ ํ๋๋ฉด ๋ฌธ์์์ execCommand ๋ฉ์๋๋ฅผ ์ฌ์ฉํ ์ ์๊ฒ ๋๋๋ฐ ์ด๊ฒ์ ์ด์ฉํด์ ๋ฌธ์์ ํธ์ง ๊ฐ๋ฅํ ์์ญ์ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค. ๋๋ถ๋ถ์ ๋ช ๋ น์ด๋ ๋ฌธ์์ ์ ํ ์์ญ์ ์
developer.mozilla.org
https://emessell.tistory.com/164
[JS] URL COPY TO CLIPBOARD, URL ์ฃผ์ ํด๋ฆฝ๋ณด๋์ ๋ณต์ฌํ๊ธฐ
https://stackoverflow.com/questions/49618618/copy-current-url-to-clipboard Copy current URL to clipboard Not sure why this has been so difficult for me today, but for some reason I cannot seem to ge..
emessell.tistory.com
'๐ Retrospect > Personal Projects' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JSTL] ftm ํ๊ทธ๋ก ๊ธ์ก ์ผํ ํ์ (0) | 2021.09.27 |
---|---|
[JS] ์นด์นด์ค ์ขํ>์ฃผ์๋ณํ API ์ฌ์ฉ (0) | 2021.09.27 |
[java] ์ค์๊ฐ ๋ฌธ์ (0) | 2021.09.08 |
[JS] ํ์ฌ ํ์ด์ง ํจ์ค ์์๋ด๊ธฐ (0) | 2021.09.08 |
[JS] localStorage ๋ก ํ์คํ ๋ฆฌ ๋จ๊ธฐ๊ธฐ (0) | 2021.09.08 |
Comment