![](/img/trans.png)
[英]Magnific popup facebook share button works just on second click
[英]Facebook Share Popup-Button Stops to Work after First Click
我的頁面上有一個Facebook按鈕。 它稱為共享彈出窗口。
問題在於按鈕僅在第一次單擊時起作用。 第二次,第三次點擊不會執行任何操作。 我總是需要刷新頁面。
我是新手。 您能幫我這個代碼嗎?
謝謝。
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'zzzzzzzzzz',
status : true,
cookie : true,
xfbml : true
});
FB.ui(
{
method: 'feed',
name: 'Bitcoin Catcher Faucet & Rotator',
link: 'http://bitcoin-catcher.com',
picture: 'http://bitcoin-catcher.com/wp-content/uploads/2015/08/icon.png',
caption: 'Only 1000+ Rewards Faucet & Rotator',
description: 'Earn FREE Bitcoins Easier & Faster! Only 1000+ Rewards per Claim!'
},
function(response) {
if (response && response.post_id) {
unhide('claim', '');
} else {
}
}
);
};
function fb_callout() {
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
}
</script>
<img alt="Share on Facebook" src="http://bitcoin-catcher.com/wp-content/uploads/2015/09/facebook-share-button.png" width="180" onclick="fb_callout();" style="cursor: pointer;" />
調用FB.ui
應該在fbAsyncInit
之外。 將其放在“共享”按鈕的click事件處理程序中。
在您的代碼示例中, 每次單擊都會加載 FB JS SDK。 這不是您想要的。
即使它是第一次使用,是因為SDK加載后會調用fbAsyncInit,這反過來-在您的示例中,再次錯誤地-通過FB.ui調用顯示提要對話框,重新加載SDK會中斷API的后續調用。 不應每次都加載SDK。
相反,您想要的是僅在頁面加載時加載一次SDK(它是異步的,因此它不會阻止瀏覽器),然后將單擊處理程序分配給調用FB.ui的按鈕。
看起來類似於以下內容
<body>
<img alt="Share on Facebook" onclick="fb_callout();" />
<script>
// Handler for click event
function fb_callout() {
FB.ui({...}, function(response) {});
}
// This is called when the SDK js file is loaded by the browser
window.fbAsyncInit = function() {
FB.init({
appId : 'zzzzzzzzzz',
status : true,
cookie : true,
xfbml : true
});
}
// This loads the FB SDK js
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
</body>
我是這樣做的,什么也沒發生...
<img alt="Share on Facebook" src="http://bitcoin-catcher.com/wp-content/uploads/2015/09/facebook-share-button.png" width="180" onclick="fb_callout();" style="cursor: pointer;" />
<div id="fb-root"></div>
<script>
function fb_callout() {
FB.ui(
{
method: 'feed',
name: 'Bitcoin Catcher Faucet & Rotator',
link: 'http://bitcoin-catcher.com',
picture: 'http://bitcoin-catcher.com/wp-content/uploads/2015/08/icon.png',
caption: 'Only 1000+ Rewards Faucet & Rotator',
description: 'Earn FREE Bitcoins Easier & Faster! Only 1000+ Rewards per Claim!'
},
function(response) {
if (response && response.post_id) {
unhide('claim', '');
} else {
}
}
);
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxxxxxxxx',
status : true,
cookie : true,
xfbml : true
});
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
}
};
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.