show message when like button is clicked?

后端 未结 1 1511
遥遥无期
遥遥无期 2021-01-29 00:07

I am using the following code to alert the user when he click the facebook like button. It is alerting the user only on Opera browser. How do I fix this problem and make it work

相关标签:
1条回答
  • 2021-01-29 00:57

    Where did you put this code ?

    For me you have to put this in the init like this :

    window.fbAsyncInit = function() {
        FB.init({
          appId  : APP_ID,
          status : true, 
          cookie : true, 
          xfbml  : true 
        });
    
        FB.Event.subscribe('edge.create',
            function(response) {
                alert("You liked the URL");
            }
        );    
    };
    

    If you have already call the FB.init, you have to use a trick like this :

    <script type="text/javascript">
        function hasFBLoad(){
            if(FB != 'undefined'){
                FB.Event.subscribe('edge.create',
                    function(response) {
                        alert("You liked the URL");
                    }
                );
            }else{
                setTimeout('hasFBLoad()', 200);
            }
        }
        hasFBLoad();
    </script>
    
    0 讨论(0)
提交回复
热议问题