Facebook Code and Comment Script

I needed to get a unique URL for each page and adapt the script that I found using the other members here.

One for the type button and one for the comment field. Is there a more elegant way to do this without a lot of 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> 
+4
source share
1 answer

If you do not put a URL when creating the code, it will by default use the current page if that is what you are trying to achieve.

0
source

Source: https://habr.com/ru/post/1438590/


All Articles