- Django Rest Framework
Front JS CRUD
[SNS 연동하기]
- html
<button type="button" class="btn btn-warning btn-outline-dark" onclick="sns_share('sns');return false;" id="sns" target="_self" title="타이틀"><span class="skip">SNS</span></a>
- JS
function sns_share(sns) {
var thisUrl = document.URL;
var snsTitle = "Beesolution 공유하기";
if( sns == 'facebook' ) {
var url = "http://www.facebook.com/sharer/sharer.php?u="+encodeURIComponent(thisUrl);
window.open(url, "", "width=486, height=286");
}
else if( sns == 'twitter' ) {
var url = "http://twitter.com/share?url="+encodeURIComponent(thisUrl)+"&text="+encodeURIComponent(snsTitle);
window.open(url, "tweetPop", "width=486, height=286,scrollbars=yes");
}
else if( sns == 'band' ) {
var url = "http://www.band.us/plugin/share?body="+encodeURIComponent(snsTitle)+"&route="+encodeURIComponent(thisUrl);
window.open(url, "shareBand", "width=400, height=500, resizable=yes");
}
}
👉 html의 버튼을 누르면 - JS에서 설정해준 thisURL 링크를 받아와 "snsTitle + URL링크"로 공유 게시글이 만들어 진다.
- 페이스북
- 트위터
- 네이버 밴드
위 3개의 SNS는 token인증 필요없이 사이트 내에서 바로 공유가 가능하다. (카카오와 인스타그램은 개발자 설정 필요)
[참고링크]
[JavaScript] 웹으로 SNS 공유하기(트위터, 페이스북, 카카오톡)
이번에 웹에서 SNS로 컨텐츠를 공유하는 기능을 만들어 보았다. 공유하고자 하는 컨텐츠URL (이미지, 웹사이트 링크 등)를 보낼 수 있다. SNS로 로그인하기 기능만큼 간간히 쓰이는 기능이므로, 기
devpad.tistory.com
'woncoding > TIL' 카테고리의 다른 글
| TIL | 12.29.목 [Github] (0) | 2022.12.30 |
|---|---|
| TIL | 12.28.수 [README.md] (0) | 2022.12.30 |
| TIL | 12.26.월 [DRF ↔️ JS CRUD] (0) | 2022.12.26 |
| TIL | 12.23.금 [사용자 피드백] (0) | 2022.12.25 |
| TIL | 12.22.목 [DRF ↔️ JS CRUD] (0) | 2022.12.25 |