'Facebook Like and Comment Code Script
I needed to get a unique url for each page and adapted a script that I found through the help of other members here.
One is for the like button and the other is for the comment box. Is there a more elegant way to do this without so much code?
<br>
<!-- start facebook like code-->
<div id="thelike"></div>
<script>
var thisurl = document.URL;
function changeCommentsUrl(newUrl){
// should refresh fb like plugin for the "newUrl" variable
document.getElementById('thelike').innerHTML='';
parser=document.getElementById('thelike');
parser.innerHTML='<div class="fb-like" data-href="'+newUrl+'" data-send="true" data-layout="button_count" data-width="400" data-show-faces="false"></div>';
FB.XFBML.parse(parser);
}
changeCommentsUrl(thisurl);
</script>
<!-- end facebook like code-->
<br>
<!-- start facebook comment code-->
<div id="thecomments"></div>
<script>
var thisurl = document.URL;
function changeCommentsUrl(newUrl){
// should refresh fb comments plugin for the "newUrl" variable
document.getElementById('thecomments').innerHTML='';
parser=document.getElementById('thecomments');
parser.innerHTML='<div class="fb-comments" data-href="'+newUrl+'" data-num-posts="10" data-width="400"></div>';
FB.XFBML.parse(parser);
}
changeCommentsUrl(thisurl);
</script>
<!-- end facebook coment code-->
<br>
Solution 1:[1]
If you don't put in a URL when generating the code, it will default to the current page if that's what you are trying to achieve.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | imp |