1

I'm trying to make my HTML and JavaScript code really organized so i'm all the JavaScript code is in different files.

When trying to insert the code into the HTML page it doesn't work:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="https://www.facebook.com/2008/fbml">
<body>

<div id="fb-root"></div>
<script src="facebook.js" type="javascript" ></script>
</body>
</html>

this is facebook.js:

window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
        appId      : 'APP_ID',                     // App ID from the app dashboard
        status     : true,                                 // Check Facebook Login status
        xfbml      : true                                  // Look for social plugins on the page
    });

    //subscribe event for facebook login
    FB.Event.subscribe('auth.statusChange', function(response) {
        alert(response.status);
    });

};

// Load the SDK asynchronously
(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'));

When i'm using the exact same script inside my html - it works great.. what am i doing wrong ?

4
  • And your console is blank? What browser are you using, and where is this script located in relation to your file? Also, the correct 'type' attribute is text/javascript. Commented Jan 17, 2014 at 8:33
  • The console says nothing.. it was the text\javascript part that was missing... write it as answer so i could accept it :) thanks Commented Jan 17, 2014 at 8:41
  • Writing a comprehensive answer, as requested. Commented Jan 17, 2014 at 8:48
  • Sorry that took so long, wanted to make sure I gave an accurate answer. Commented Jan 17, 2014 at 9:05

2 Answers 2

2

Try type="text/javascript" in the script tag.

Also, is your .js file in the same folder as your .html file? If you've put the JavaScript in a folder you will need to do something like this:

<script src="FolderName/facebook.js" type="text/javascript"></script>

Sign up to request clarification or add additional context in comments.

Comments

1

As I noted in my comment above, one of the correct values when dealing with a javascript content type is text/javascript, as "noted" in the w3c spec.

I said above it is 'one' of the correct values; this is due to the MIME-type listing specified here, and accessed here(as a note, the MIME-type listing currently appears to be down, so the above page is of a web archive); the MIME-type listing specifies that 'text/javascript' is obsolete, and by clicking the relevant RFC(4329), it appears the now-correct MIME-type is application/javascript.

1 Comment

Of course, I could be wrong, but that's what I managed to find.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.