Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6014661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:43:28+00:00 2026-05-23T02:43:28+00:00

I have a javascript for facebook integration, and it works perfectly when I include

  • 0

I have a javascript for facebook integration, and it works perfectly when I include it written in the body of my HTML. Now, since I have quite a few pages that all require the facebook auth script, I saved it in a seperate file and include it in all my pages, but when I do this, the script seems to cease to function. Here’s the code

//Ajax XML Loaders
var xmlhttp;
function loadXMLDoc(url,cfunc)
    {
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=cfunc;
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
}
window.fbAsyncInit = function() {
    FB.init({appId: 'xxxxxx', status: true, cookie: true, xfbml: true});

    /* All the events registered */
    FB.Event.subscribe('auth.login', function(response) {
        // do something with response
        login();
    });
    FB.Event.subscribe('auth.logout', function(response) {
        // do something with response
        logout();
    });

    FB.getLoginStatus(function(response) {
        if (response.session) {
            // logged in and connected user, someone you know
        }
    });
};
(function() {
    var e = document.createElement('script');
    e.type = 'text/javascript';
    e.src = document.location.protocol +
        '//connect.facebook.net/en_US/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e);
}());
function login(){
    //Fire the PHP Facebook Auth Script
    loadXMLDoc('http://www.website.com/scripts/php/facebook_auth.php',function()
        {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
            if (xmlhttp.responseText == "Success"){
                window.location.reload;
            }else{
                window.location = "http://www.website.com/login_failed.php";    
            }
        }
    });
}
function fblogoutClick(){
    FB.logout(function(response) {

    }); 
}
function logout(){
    //Fire the PHP Logout Script
    loadXMLDoc('http://www.website.com/scripts/php/logout_exec.php',function()
        {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
            if (xmlhttp.responseText == "Success"){
                window.location.reload;
            }else{
                window.location = "http://www.website.com/logout_failed.php";   
            }
        }
    });
}

And I put this in the head:

<script src="http://www.thehoppr.com/scripts/javascript/facebook_login.js"></script>

The FB login event is fired by a button click, but like I said, if I include this within the body, it works fine, but if I save it externally and load it in the head or body, it ceases to function and I’m not exactly sure why.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:43:29+00:00Added an answer on May 23, 2026 at 2:43 am

    The only reason this would happen would be if the code were not included properly. In terms of the code actually getting run, there’s no significant difference between

    <script>
    foo();
    </script>
    

    and

    <script src="foo.js"></script>
    

    …where foo.js contains foo();, provided those tags are in the same place. If you put the inline tag in one place, but you put the external reference tag elsewhere, then of course there’s a difference in terms of where the script is.

    (There are differences, most notably that the browser doesn’t have to read through the script code looking for the ending script tag, which is a Good Thing; but that probably isn’t relevant here.)

    The most common errors including scripts are:

    • Not including the ending </script> tag.
    • Trying to use a self-closing tag, e.g. <script src="foo.js" /> which does not work.
    • Getting the path to the JavaScript file wrong. 🙂
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have JavaScript that computes and injects HTML into my DOM for the Facebook
I downloaded the script from emposha.com/javascript/fcbklistselection-like-facebook-friends-selector.html and made a few modifications, as the source
I have a website with Facebook integration. The homepage has a few Like buttons,
I have been working on facebook application and you know on facebook native javascript
I have javascript code embedded inside a html template file. When I load this
I have created simple javascript widget where login happens using Facebook Single Sign On.
I have just implemented Facebook Authentication on my website using Facebook JavaScript. If user
I am trying to include Facebook's Javascript SDK (the all.js file from http://connect.facebook.com/en_US/all.js )
I have a small doubt , I am using facebook javascript sdk to authenticate
I have made a game using HTML5 Canvas Element, Javascript for facebook. You can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.