Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

❤️‍🔥 링크 복사하기 #50

Open
leemember opened this issue Nov 29, 2022 · 0 comments
Open

❤️‍🔥 링크 복사하기 #50

leemember opened this issue Nov 29, 2022 · 0 comments

Comments

@leemember
Copy link
Owner

leemember commented Nov 29, 2022

https://abangpa1ace.tistory.com/255

💙 document.execCommand (deprecated)

export const clip = (): void => {
  let url = '';
  const textarea = document.createElement("textarea");
  document.body.appendChild(textarea);
  url = window.document.location.href;
  textarea.value = url;
  textarea.select();
  document.execCommand("copy");
  document.body.removeChild(textarea);
}
  • url 변수를 생성한다.
  • textarea는 임시로 생성하는 textarea 요소를 가르킨다. 이를 body에 추가한다.(appendChild)
  • url에 현재 주소를 할당한다.(window.document.location.href) 그리고, textarea의 value에 이 url 값을 넣어준다.
  • textarea를 선택한다.(select) 그 다음에, execCommand('copy') 메서드로 클립보드에 복사한다.
  • 마지막으로, 불필요한 textarea 를 removeChild() 로 지워준다.

현재 링크 위치

const url = document.URL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant