jQuery的。点击HTML按钮获得点击Facebook的喜欢按钮 [英] jQuery. Click HTML button to get clicked Facebook like button
问题描述
我有2个按钮,1个简单的和其他类似Facebook的按钮,我想打在单击我的简单的按钮后,它激活(点击)Facebook的按钮太多,但它不会工作。我用这个code:
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" />
这是其他code.After我的Like按钮点击它提醒我只是喜欢点击按钮,但此行不工作 $(这)一个.remove();
。 (但我需要像我在第一种情况下说,点击测试按钮来获得点击FB-Like按钮。)
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>
也许从这个code部分线路需要,像这些 window.fbAsyncInit =功能(E){
?
FB.Event.subscribe('edge.create',函数(响应){
推荐答案
不幸的是,你将无法点击Facebook的喜欢按钮这样的。
Sadly, you won't be able to click the Facebook like button this way.
这是到位的安全限制prevent你点击,你不希望第三方网站什么。下面是关于点击劫持和的同源策略。
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.
这篇关于jQuery的。点击HTML按钮获得点击Facebook的喜欢按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!