Note that there are some explanatory texts on larger screens.

plurals
  1. POExternal Javascript Doesn't Interact with Button Clicks?
    primarykey
    data
    text
    <p>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</p> <pre><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 &amp;&amp; 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 &amp;&amp; xmlhttp.status==200) { if (xmlhttp.responseText == "Success"){ window.location.reload; }else{ window.location = "http://www.website.com/logout_failed.php"; } } }); } </code></pre> <p>And I put this in the head:</p> <pre><code>&lt;script src="http://www.thehoppr.com/scripts/javascript/facebook_login.js"&gt;&lt;/script&gt; </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload