简体   繁体   English

当我单击按钮时,如何显示我的Facebook对话框?

[英]How can I get my Facebook dialog to show up when I click the button?

I want to add a button to my site that, when clicked, will bring up a Facebook dialog box so the user can post a message to their Facebook timeline. 我想在我的网站上添加一个按钮,单击该按钮将弹出一个Facebook对话框,以便用户可以将消息发布到其Facebook时间线。

I've been reading through the documentation I think my code is correct but the button doesn't work. 我一直在阅读文档,我认为我的代码是正确的,但是该按钮不起作用。 When I click the button nothing happens. 当我单击按钮时,什么也没有发生。

My code: 我的代码:

    <html>

    <body>
     <div id="fb-root"></div>
        <script>

            function post_to_facebook()
            {
              window.fbAsyncInit = function() {
                FB.init({
                  appId      : '********',
                  status     : true,
                  xfbml      : true
                });
                FB.ui(
                  {
                   method: 'feed',
                   name: 'The Facebook SDK for Javascript',
                   caption: 'Bringing Facebook to the desktop and mobile web',
                   description: (
                      'A small JavaScript library that allows you to harness ' +
                      'the power of Facebook, bringing the user\'s identity, ' +
                      'social graph and distribution power to your site.'
                   ),
                   link: 'https://developers.facebook.com/docs/reference/javascript/',
                   picture: 'http://www.fbrell.com/public/f8.jpg'
                  },
                  function(response) {
                    if (response && response.post_id) {
                      alert('Post was published.');
                    } else {
                      alert('Post was not published.');
                    }
                  }
                );
              };

              (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'));
            }
        </script>

    <input type="button" onclick="post_to_facebook()" value="Post my score to Facebook" />
    </body>
    </html>

Here's a screenshot of my browser after I click the button: 这是单击按钮后浏览器的屏幕截图: 在此处输入图片说明

Are you testing on a local computer? 您是否正在本地计算机上进行测试? Try saving the page on a server and then opening it. 尝试将页面保存在服务器上,然后将其打开。 It should work. 它应该工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使HTML元素被JavaScript隐藏,并在单击按钮时显示? - How can I make HTML elements be hidden by JavaScript, and show up when I click a button? 单击按钮后如何在脚本中显示我的数字和财富 - How can i get my numbers and fortunes to show on this script on button click 当我点击转向按钮时,我希望显示姓名、年龄和位置? 如何访问 function 中的 nextContestant 变量? - When I click on the turn button I want the name, age and location to show up? How to get access to the nextContestant variable in the function? 单击按钮时如何重定向到我的网站? - How can I redirect to my website when I click a button? 单击按钮时如何显示一些文本字段? - How i can show some textfield when click button? 单击按钮时如何显示工具提示 - how can i show a tooltip when click a button 如何让我的消息正确显示? - How can I get my messages to show up properly? 当我点击它时,如何让我的阅读更多按钮显示更多文本(javascript/css/html)? - How do I get my read more button to show more text when i click on it (javascript/css/html)? 单击按钮时如何显示div - How to show a div when I click on a button 单击侧边栏时如何隐藏我的表格? 并且当我单击按钮显示另一个表时,当前打开的表会关闭吗? - How can I hide my table when I click in the sidebar? and Also when I click the button to show another table the current open table will close?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM