按下按钮后,我有以下脚本来激活 facebook 对话框屏幕。尽管有一些用户操作,但弹出窗口仍然被阻止。我搜索了很多关于这个问题,但我不知道如何解决这个问题:(我希望有人能帮助我!
该脚本由一个按钮触发:
onClick="fb_callout();
脚本:
<div id="facebook-root"></div>
<script>
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : '', // App ID from the App Dashboard
channelUrl : '', // Channel File for x-domain communication
status : true, // check the login status upon init?
cookie : true, // set sessions cookies to allow your server to access the session?
xfbml : true // parse XFBML tags on this page?
});
// Additional initialization code such as adding Event Listeners goes here
FB.ui(
{
method: 'feed',
//display: 'iframe',
name: '',
link: '',
picture: '',
caption: '',
description: ''
},
function(response) {
if (response && response.post_id) {
window.location.href = '';
} else {
alert('');
}
}
);
};
// Load the SDK Asynchronously
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/nl_NL/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
}
</script>
根据您(CBroe)的指示,我稍微更改了脚本。现在它似乎工作了!:) 弹出窗口出现没有问题。
结果:
<div id="facebook-root"></div>
<script>
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : '', // App ID from the App Dashboard
status : true, // check the login status upon init?
cookie : true, // set sessions cookies to allow your server to access the session?
xfbml : true // parse XFBML tags on this page?
});
// Additional initialization code such as adding Event Listeners goes here
};
// Load the SDK Asynchronously
(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";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function fb_callout()
{
FB.ui(
{
method: 'feed',
name: '', // name of the product or content you want to share
link: '', // link back to the product or content you are sharing
picture: '', // path to an image you would like to share with this content
caption: '', // caption
description: '' // description of your product or content
},
function(response) {
if (response && response.post_id) {
window.location.href = '';
} else {
alert('Post was not published.');
}
}
);
}
</script>