I have the following feature where the user can share a feed. The below code gets block by pop up blockers on most browsers. I’ve seen several post on stack overflow about this issue. One recommended using the onclick which i’ve tried. I’ve noticed that if my facebook sdk fails i don’t get the popup block. What is the best plan of attack. I’m using php.
<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>
Currently you are loading the SDK onclick – why?
You want to execute the function that opens a popup –
facebookInitin your case – onclick.