오래된 게시판 스킨의 트위터 공유 기능이 잘 동작하지 않는 경우가 있습니다. 아마도 트위터에서 공유 방식이 변경되어서 그런 것 같은데 이를 반영하지 못해서 그런 것 같은데 제가 스케치북5 스킨의 예를 들어 한번 수정한 것을 적어 보겠습니다.
*의외로 최신 스킨에도 예전 코드가 그대로 사용되는 경우가 많아 공유가 안되고 있습니다.
/js/board.js 파일에 sns공유하는 코드가 있습니다.
라인 수는 제가 가진 파일 기준이라 조금씩 다를 수 있습니다.
// To SNS
bd.find('.to_sns a').click(function(){
var t = $(this);
var type = t.data('type');
var p = t.parent();
var href = p.data('url');
var permanentUrl = p.data('permanenturl');
var title = p.data('title');
var img = bd.find('div.xe_content img:first').attr('src');
if(!type){
return;
} else if(type=="facebook"){
var loc = '//www.facebook.com/sharer/sharer.php?u='+href+'&t='+title;
} else if(type=="twitter"){
loc = '//twitter.com/home?status='+encodeURIComponent(title)+' '+href;
} else if(type=="google"){
loc = '//plus.google.com/share?url='+href;
} else if(type=="pinterest"){
if(!img){
alert('No Image!');
return false;
};
loc = '//www.pinterest.com/pin/create/button/?url='+href+'&media='+img+'&description='+encodeURIComponent(title);
} else if(type=="kakaostory"){
loc = 'https://story.kakao.com/share?url='+encodeURIComponent(href);
} else if(type=="band"){
loc = 'http://www.band.us/plugin/share?body='+encodeURIComponent(title)+'%0A'+encodeURIComponent(href);
} else if(type=="kakao"){
if(img){
Kakao.Link.sendTalkLink({
label:title,
image:{
src:img,
width: '300',
height: '200'
},
webLink:{
text:permanentUrl,
url:href
}
});
} else {
Kakao.Link.sendTalkLink({
label:title,
webLink:{
text:permanentUrl,
url:href
}
});
};
return false;
};
window.open(loc);
return false;
});
위 코드 내용 중에 트위터 부분 1줄을 바꿔야 합니다.
// To SNS
bd.find('.to_sns a').click(function(){
var t = $(this);
var type = t.data('type');
var p = t.parent();
var href = p.data('url');
var permanentUrl = p.data('permanenturl');
var title = p.data('title');
var img = bd.find('div.xe_content img:first').attr('src');
if(!type){
return;
} else if(type=="facebook"){
var loc = '//www.facebook.com/sharer/sharer.php?u='+href+'&t='+title;
} else if(type=="twitter"){
loc = '//twitter.com/share?text='+encodeURIComponent(title)+' '+'&url='+href;
} else if(type=="google"){
loc = '//plus.google.com/share?url='+href;
} else if(type=="pinterest"){
if(!img){
alert('No Image!');
return false;
};
loc = '//www.pinterest.com/pin/create/button/?url='+href+'&media='+img+'&description='+encodeURIComponent(title);
} else if(type=="kakaostory"){
loc = 'https://story.kakao.com/share?url='+encodeURIComponent(href);
} else if(type=="band"){
loc = 'http://www.band.us/plugin/share?body='+encodeURIComponent(title)+'%0A'+encodeURIComponent(href);
} else if(type=="kakao"){
if(img){
Kakao.Link.sendTalkLink({
label:title,
image:{
src:img,
width: '300',
height: '200'
},
webLink:{
text:permanentUrl,
url:href
}
});
} else {
Kakao.Link.sendTalkLink({
label:title,
webLink:{
text:permanentUrl,
url:href
}
});
};
return false;
};
window.open(loc);
return false;
});
위와 같이 바꿔주면 트위터 공유가 정상적으로 됩니다. 여기 라이믹스 꿀팁도 방금 고쳤습니다. 예전 코드 그대로 두면 트위터 공유가 안되고 그냥 트위터 홈화면으로 이동하게 됩니다.
7월 15일 오전 11시 30분 경 수정되었습니다. url 부분이 조금 바뀌었습니다.


덕분에 트위터도 이제 돌아갑니다. 그런데 왜 저는 내용이 깔끔하게 안나올까요.