简体   繁体   中英

Javascript alert on facebook like page

I want to show an alert like "You liked the page" when my users click on "Facebook Like Button" in my web site.

I tryed to add onClick="alert("You liked it");" on

<div class="fb-like" data-href="https://developers.facebook.com/docs/plugins/" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>

But it dosen't work.

I'm a student sorry for my fail, how i can do it in Javascript?

Thanks alot

Maybe this will help you: https://developers.facebook.com/docs/plugins/like-button

If i got it right, this is the code the fb-button loads: https://connect.facebook.net/de_DE/sdk.js#xfbml=1&version=v2.6 . Maybe you find the declaration of the button, where you can add your code.

That's because you've wrapped the text around double quotes. Use single ones instead:

onclick="alert('You liked it');"

I will also show you how you can do this in JavaScript:

Firstly you need to give an id to your button so you can reference it in JS:

<div id='like-btn' class="fb-like" data-href="https://developers.facebook.com/docs/plugins/" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>

Then you can go to your JavaScript file and do the following:

var likeBtn = document.getElementById('like-btn');
likeBtn.onclick = function(){
    alert("You clicked it");
}

EDIT: Facebook provides callbacks for events like, liking a page.

FB.Event.subscribe('edge.create', function() { alert('You liked it'); });

You can read more about Facebook Event Subscription here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM