简体   繁体   English

如何阻止我的Facebook共享窗口被弹出窗口阻止程序阻止?

[英]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: 您需要做两件事:

  • Load the JS SDK on page load, NOT on user interaction. 在页面加载时加载JS SDK,而不是在用户交互时加载。
  • Call 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.

相关问题 如何测试打开的命名窗口或被弹出窗口阻止程序阻止的命名窗口? - How can I test if a named window is opened or was blocked by a popup blocker? facebook / twitter分享按钮如何避免被弹出窗口阻止程序阻止? - How facebook/twitter share buttons avoid being blocked by popup blockers? 浏览器弹出窗口阻止程序阻止的打印窗口 - Print window blocked by browser popup blocker 文件下载被浏览器弹出窗口阻止程序阻止 - File download is being blocked by the browser popup blocker 如何在使用window.open时停止浏览器弹出窗口阻止程序 - How to stop browser popup blocker when using window.open 如何在 Chrome 中检测弹出窗口阻止程序? - How do I detect popup blocker in Chrome? 阻止子窗口被弹出窗口拦截器捕获 - prevent child window from being caught by popup blocker 如何使用window.open创建一个不确定延迟的弹出窗口(对于Social Auth)而没有弹出窗口阻止程序阻止它 - How do I create an indeterminately delayed popup (for Social Auth) with window.open without a popup blocker stopping it 如果用户已登录FB,如何阻止我的Facebook登录弹出窗口出现? - How do I stop my Facebook login popup from appearing if user is already logged into FB? IE弹出窗口阻止程序阻止了Javascript window.open - Javascript window.open is blocked by IE popup blocker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM