How to manage 'Like' button for URLs that can change slightly?

谁都会走 提交于 2019-12-08 04:05:10

问题


I have a like button on each page in a wallpaper site. There is an option to edit the title of the wallpaper. Hence, the URL of the page changes as well, like it happens in Stack Overflow. In Stack Overflow, when the title of the question changes, the old URL is redirected permanently to the new URL. The same logic is implemented in my site.

The problem is, say if there are 10 likes for a wallpaper page

http://www.example.com/1/old-title-wallpaper

If the title is changed slightly to 'new title', the URL changes to

http://www.example.com/1/new-title-wallpaper

In the new page, the like count becomes 0. Is there a way to make the Like button detect 301 redirection.


回答1:


The like button uses the og:url tag. On your new page you need to keep the old og:url value.




回答2:


This means you are not giving an explicit url for the like button code.. Hence the FB server picks the current url of the page where the like button is placed.. Check the iFrame of like button and see that you mention the data-href there .. Sample Code:

`<div id="fb-root"></div>
 <script>(function(d, s, id) {

     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/all.js#appId=xxxx0&xfbml=1";
     fjs.parentNode.insertBefore(js, fjs);
  }
   (document, 'script', 'facebook-jssdk'));
  </script>

  <div class="fb-like" data-href="http://xxx.com" data-send="true" data-width="450"    data-show-faces="true">
  </div>

Link to Like Pluggin http://developers.facebook.com/docs/reference/plugins/like/

Also, you can use Metadata tags to explicitly make the FB server pick the url as desired by you .. Use Open Graph tag og:url for that See http://developers.facebook.com/docs/opengraph/



来源:https://stackoverflow.com/questions/7425192/how-to-manage-like-button-for-urls-that-can-change-slightly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!