0

我需要确保我的 Facebook Connect 代码在点击事件上运行,但无论我如何尝试,我都无法让它工作。它必须很简单,但我就是想不通。这是我最近的尝试,但是如果我在 FB.Event.subscribe 之后将警报放入代码中,它永远不会到达它。该代码确实从 document.ready 中运行,但我需要它在单击事件上运行。实时 URL 是 lovelyjubbly.info/en-GB/Gameplan。

    <div class="facebookconnect">
            <div id="fb-root"></div>

            <script language="javascript" type="text/javascript" src="http://connect.facebook.net/@Thread.CurrentThread.CurrentUICulture.Name.Replace('-', '_')/all.js"></script>

            <script type="text/javascript">

                $(document).ready(function () {

                    window.FB.init({ appId: 'abc', status: true, cookie: true, xfbml: true });

                });

                function fbclick()
                {
                    FB.Event.subscribe('auth.login', function (response) {
                        alert("loggedin");
                        var isUserAuthenticated = @User.Identity.IsAuthenticated.ToString().ToLower();

                        if ((response.status == 'connected') && (isUserAuthenticated == false)){
                            window.location.href = '@Account.Urls.FacebookConnect()';
                        }
                    });
                }

            </script>

            <script>(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/" + @Thread.CurrentThread.CurrentUICulture.Name.Replace('-', '_') + "/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

           <fb:login-button onclick="fbclick()" autologoutlink="false" perms="email" id="fbLogin">

           </fb:login-button>

        </div><br />

编辑:使用 live() 方法,似乎仍然不起作用:

    <div class="facebookconnect">
            <div id="fb-root"></div>

            <script language="javascript" type="text/javascript" src="http://connect.facebook.net/@Thread.CurrentThread.CurrentUICulture.Name.Replace('-', '_')/all.js"></script>

            <script type="text/javascript">

                $(document).ready(function () {

                    window.FB.init({ appId: 'abc', status: true, cookie: true, xfbml: true });

                });

                $("#fbLogin").live("click", function(){ 
                    FB.Event.subscribe('auth.login', function (response) {
                        alert("loggedin");
                        var isUserAuthenticated = @User.Identity.IsAuthenticated.ToString().ToLower();

                        if ((response.status == 'connected') && (isUserAuthenticated == false)){
                            window.location.href = '@Account.Urls.FacebookConnect()';
                        }
                    });
                }); 


            </script>

            <script>(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/" + @Thread.CurrentThread.CurrentUICulture.Name.Replace('-', '_') + "/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

           <fb:login-button autologoutlink="false" perms="email" id="fbLogin">

           </fb:login-button>

        </div><br />
4

1 回答 1

1

利用

$(yourselector).live('click', function() {
   //fb stuff
});

我不太记得为什么会这样,但似乎确实如此。

于 2012-08-21T23:43:33.983 回答