1

html我在一个文件中试用了 Javascript SDK ,一切正常。然后将相同的代码移动到一个.xhtml文件中,它完全停止了工作。

代码如下:

从一个文件移动test.html到另一个文件test.xhtml并停止工作

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    </head>
    <body>
        <div id="fb-root"></div>
        <script>
            // Load the SDK Asynchronously
            (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));

            // Init the SDK upon load
            window.fbAsyncInit = function() {
                FB.init({
                    appId      : '365436556863538', // App ID
                    channelUrl : '//'+window.location.hostname+'/channel', // Path to your Channel File
                    status     : true, // check login status
                    cookie     : true, // enable cookies to allow the server to access the session
                    xfbml      : true  // parse XFBML
                });

                // listen for and handle auth.statusChange events
                FB.Event.subscribe('auth.statusChange', function(response) {
                    if (response.authResponse) { 
                        FB.api('/me', function(response){
                            if (response.name) {
                                $("#username").html("<img src='https://graph.facebook.com/" + response.id + "/picture'/><div>" + response.name  +"</div>");

                            }
                        })
                        $('#auth-loggedout').hide();
                        $('#auth-loggedin').show();
                    } else {
                        // user has not auth'd your app, or is not logged into Facebook
                        $('#auth-loggedout').show();
                        $('#auth-loggedin').hide();
                    }
                });

                // respond to clicks on the login and logout links
                document.getElementById('auth-loginlink').addEventListener('click', function(){
                    FB.login(function(response) {
                       // handle the response
                     }, {scope: 'email'});
                });
                document.getElementById('auth-logoutlink').addEventListener('click', function(){
                    FB.logout();
                }); 
            } 
        </script>
        <div id="auth-status">
            <div id="auth-loggedout">
                <a href="#" id="auth-loginlink">Login</a>
            </div>
            <div id="auth-loggedin" style="display:none">
                (<a href="#" id="auth-logoutlink">logout</a>)

            </div>
        </div>
        <div>
            <div id="username"></div>
        </div> 
    </body>
</html>

我可以在控制台窗口中找到它:

未捕获的 SyntaxError:意外的标识符

window.script1342849602887=1;

4

0 回答 0