show message when like button is clicked?

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 with all browsers ?

<script>
FB.Event.subscribe('edge.create',
    function(response) {
        alert("You liked the URL");
    }
);
</script>

I can also use Jquery.

Answers:

Answer

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>

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.