1
我有以下功能,用戶可以共享一個供稿。下面的代碼在大多數瀏覽器上都會彈出阻止程序。關於這個問題,我已經看過幾篇關於堆棧溢出的文章。一個建議使用我試過的onclick。我注意到,如果我的臉譜sdk失敗,我不會彈出塊。什麼是最好的攻擊計劃。我使用的是PHP。Facebook上的彈出式窗口阻止供稿共享
<a class="facebook" href="#" onclick='loadSdk(); return false;'></a>
<script>
function loadSdk(){
window.fbAsyncInit = function() {
FB.init({
appId : '123', // App ID
channelUrl : 'http://mysite.com/facebook', // Channel File
// status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
if (typeof facebookInit == 'function') {
facebookInit();
}
FB.api('/me', function(user) {
if (user) {
var image = document.getElementById('image');
image.src = 'https://graph.facebook.com/' + user.id + '/picture';
var name = document.getElementById('name');
name.innerHTML = user.name
}
});
};
// Load the SDK Asynchronously
(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));
}
function facebookInit(){
var publish = {
method: 'feed',
message: '',
name: '',
caption: '',
description: (
),
link: 'http://mysite.com/',
picture: 'http://mysite.com/fblogo.png',
actions: [
{ name: '123', link: 'http://www.mysite.com/' }
],
user_message_prompt: 'Share your thoughts'
};
FB.ui(publish, null);
}
</script>
當前您正在加載SDK onclick - 爲什麼?您想要執行打開彈出窗口的功能 - 您的案例中命名不佳的'facebookInit' - 點擊。 – CBroe
啊,你的權利。如果你願意我會投票。對於其他人來說,總結一下,我試圖加載SDK onclick。當我在加載頁面時加載sdk,然後發佈onclick – frosty