问题
I have 2 buttons, 1 simple and other Facebook like button, I want to make that after my simple button is clicked, It activated(clicked) Facebook button too, but It wont work. I've used this code:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script>
$(function(){
$("#test").click(function(){
$("#fb-root").click(); //this doesn't click Like button
alert("Like is clicked"); // this alert when button is clicked
});
});
</script>
<div class="fb-like" data-href="https://facebook.com/myPage" data-layout="button" data-action="like" data-show-faces="false" data-share="false" ></div>
<input type="button" id="test" name="test" value="Test" />
This is other code.After my Like button is clicked It alert "I just clicked like button", but this line not working $(this).remove();
. (But I need to make like I said in first case. Click "Test" button to get clicked "fb-like" button.)
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function(e) {
FB.Event.subscribe('edge.create', function(response) {
$(this).remove(); // I used this to remove button after clicking, but not working
alert('I just clicked like button');
});
};
(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#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
Maybe some lines from this code are needed, something like these window.fbAsyncInit = function(e) {
FB.Event.subscribe('edge.create', function(response) {
?
回答1:
Sadly, you won't be able to click the Facebook like button this way.
This is a security limitation in place to prevent you from clicking anything on a third party site that you don't want to. Here's more information about clickjacking and the same-origin policy.
来源:https://stackoverflow.com/questions/20765539/jquery-click-html-button-to-get-clicked-facebook-like-button