[英]How do I stop my Facebook share window from being blocked by popup-blocker?
I have my Facebook share window appearing when a function is called onClick of the Facebook share button. 当调用Facebook共享按钮的onClick函数时,我出现了我的Facebook共享窗口。
The problem is that the Facebook window attempts to appear but is blocked by popup-blocker. 问题是Facebook窗口试图出现,但被弹出窗口阻止程序阻止了。
This is my first time creating a share window. 这是我第一次创建共享窗口。 Is there a simple solution to bypass the popup blocker?
有一个简单的解决方案绕过弹出窗口阻止程序吗?
Here is the button that triggers the function: 这是触发功能的按钮:
<button class="share-now" onclick="fb_callout();">
And here is the function that is called: 这是所谓的函数:
<script>
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));
}
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : '162280254223002', // App ID from the App Dashboard
xfbml : true,
version : 'v2.5',
status : true
});
// Additional initialization code such as adding Event Listeners goes here
FB.ui(
{
method: 'feed',
href: 'http://www.example.com',
name: 'Example',
link: 'http://www.example.com',
picture: 'http://image.png',
caption: 'Caption',
description: 'words go here'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
};
</script>
Right now you are trying to open a popup not on user interaction, but in an asynchronous callback function. 现在,您尝试打开的弹出窗口不是在用户交互上,而是在异步回调函数中。 Of course the popup blocker detects that and blocks the popup (for a good reason).
当然,弹出窗口阻止程序会检测到该情况并阻止弹出窗口(有充分的理由)。 You need to do two things:
您需要做两件事:
FB.ui
directly on user interaction. FB.ui
It should be the only thing in the fb_callout
function. fb_callout
函数中唯一的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.