Skip to content

Commit

Permalink
Feat: http에서도 클립보드 사용가능하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
navyjeongs committed Nov 21, 2023
1 parent 237d4df commit fb4cb75
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,20 @@ const Header = () => {
await navigator.clipboard.writeText(channelLink as string);
alert('클립보드에 초대링크가 복사되었습니다.');
} catch (e) {
alert('복사에 실패하였습니다. 다시 시도해주세요');
// execCommand 사용
const textArea = document.createElement('textarea');
textArea.value = `${channelLink}`;
document.body.appendChild(textArea);
textArea.select();
textArea.setSelectionRange(0, 99999);
try {
document.execCommand('copy');
} catch (err) {
console.error('복사 실패', err);
}
textArea.setSelectionRange(0, 0);
document.body.removeChild(textArea);
alert('텍스트가 복사되었습니다.');
}
};

Expand Down

0 comments on commit fb4cb75

Please sign in to comment.