Update FB:Like URL Dynamically using JavaScript

前端 未结 5 786
感动是毒
感动是毒 2020-12-04 18:25

i\'d like to change the URL to like of an FB:Like button dynamically using javascript.

right now i\'ve only been able to change the href attribute o

5条回答
  •  遥遥无期
    2020-12-04 19:17

    another solutions :

    instead of your fb:like object, write a FB iframe in your html like this :

    
    

    and now you can change with javascript with this function :

    function setUrl(url)
    {
        sUrl = url;
        url = "http://www.facebook.com/plugins/like.php?href="+sUrl+"&layout=button_count&show_faces=false&width=400&action=like&font=arial&colorscheme=light";
        document.getElementById('face').setAttribute('src', url);
        //alert("url : "+url);
    }
    

    when you change the src, the FB iframe is updated.

提交回复
热议问题