함수 실행은 이렇게 호출만
<input type="button" onClick="shareFacebook();" value="facebook" />
페이스북 URL 공유하기
페이스북에서 URL을 공유하는 링크가 제공되고 있다.
URL에 파라미터를 이용해서 링크 공유가 가능하다.
Javasript window.open을 이용해서 페이스북 공유할 새로운 팝업을 띄워서 해당 URL을 공유하는 방식이다
페이스북 공유 URL : http://www.facebook.com/sharer.php?u=공유할URL&t=공유URL타이틀
<script>
function shareFacebook() {
let url = encodeURIComponent('공유할url');
let title = '공유될 url 타이틀';
window.open(`http://www.facebook.com/sharer.php?u=${url}&t=${title}`, 'popup제목', 'width=400, height=400');
}
</script>
트위터 URL 공유하기
트위터의 경우도 URL을 공유하는 링크가 마찬가지로 제공된다.
마찬가지로 URL에 파라미터를 던져줘야 한다.
트위터 공유 URL : https://twitter.com/intent/tweet?url=공유할URL&text=공유URL타이틀
<script>
function shareTwitter() {
let url = encodeURIComponent('공유할url');
let title = '공유될 url 타이틀';
window.open(`https://twitter.com/intent/tweet?url=${url}&text=${title}`,'popup제목', 'width=400, height=400');
}
</script>
출처: https://ordinary-code.tistory.com/73 [김평범's OrdinaryCode]
'코딩 공부 > 기능' 카테고리의 다른 글
sns 공유 구현 -카카오톡 (0) | 2021.11.09 |
---|