[JS] URL ํด๋ฆฝ๋ณด๋“œ์— ๋ณต์‚ฌํ•˜๊ธฐ
728x90

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฒ„ํŠผ ํด๋ฆญ์‹œ

ํ˜„์žฌ ํŽ˜์ด์ง€์˜ 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);
	}

ํ•จ์ˆ˜ ์‹คํ–‰์‹œ ์ž„์‹œ๋กœ URL์„ ๋‹ด๋Š” input์„ ์ƒ์„ฑํ•˜๊ณ  ๋ณต์‚ฌ ํ›„ ์‚ญ์ œํ•œ๋‹ค.

 

document.execCommand("copy");

ํด๋ฆฝ๋ณด๋“œ ๋ณต์‚ฌ์˜ ํ•ต์‹ฌ! ํด๋ฆฝ๋ณด๋“œ์— ํ˜„์žฌ ์„ ํƒ ์˜์—ญ์˜ ๋‚ด์šฉ์„ ๋ณต์‚ฌํ•œ๋‹ค.

 

 

 

ํด๋ฆญํ›„ ํŒ์—…์„ ๋‹ซ๊ณ  ๋ฉ”๋ชจ์žฅ์— ๋ถ™์—ฌ๋„ฃ๊ธฐ ํ–ˆ์„ ๋•Œ URL์ด ์ž˜ ๋ณต์‚ฌ๋œ ๊ฒƒ ํ™•์ธ.

 

 

๐Ÿ“ƒ ์ฐธ๊ณ 

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

 

728x90