I use FireFox as my main browser, especially when testing out my site, Avoru. However, when checking to see if my code was working properly across other major browsers (Google Chrome, Opera, and Safari), I found that none of my custom javascript seemed to work. Although the functions and code were clear in the page source, using typeof returned an 'undefined' value for all my functions.
What is the root of this problem? If it makes any difference, I use both the Prototype and jQuery libraries for my code, as well as load all javascript at the bottom of the page (for speed reasons). Thanks!
EDIT: Here is some of the code.
// === var $j frees up the $ selector. === //
var $j = jQuery.noConflict();
// === Function: loading(); and loaded(); Manually controls the #loading element. === //
function loading(){
$j('#load_ovrly').css({'display':'block'});
$j('#loader').fadeTo('fast',1);
}
function loaded(){
$j('#load_ovrly').css({'display':'none'});
$j('#loader').fadeTo('fast',.0001);
}
// === Function: content(); Using everything after the #, the hash is processed and requested. === //
function content(theHash){
var hashIndex = theHash.indexOf('-');
var commaIndex = theHash.indexOf(',');
// === Split the Hash accordingly. === //
if((hashIndex > commaIndex) || (commaIndex == -1 && hashIndex == -1)) newHash = theHash.split(',');
if((commaIndex > hashIndex) || (commaIndex == -1 && hashIndex != -1)) newHash = theHash.split('-');
// === Set some extra variables for proofing. === //
var url = newHash[0]+".php";
// === Get parameters if there are any. === //
if(newHash[1]){
var Json = jsonify(newHash[1]);
var pars = "p="+Json;
}else{
var pars = "p={\"forcepars\":\"true\"}";
}
// === Finally request the page. === //
request(url,pars);
}
// === Function: jsonify(); Turns the leftover hash from content(); into valid JSON. === //
function jsonify(str){
var Json = "{";
var split = str.split(",");
for(var a = 0; a < split.length; a++){
if(a > 0){Json = Json+",";}
var b = split[a].split(":");
if(b[1] != undefined) Json = Json+"\""+b[0]+"\":\""+b[1]+"\"";
}
return Json+"}";
}
// === Function: AJAX(); Sends an ajax request given the url, some parameters, and the onComplete. === //
function AJAX(url,parameters,complete){
$j.ajax({
type: 'POST',
url: url,
data: parameters,
complete: function($data){
var data = $data.responseText;
complete(data);
}
});
}
// === Function: request(); Takes the properly formatted url and parameters and requests the page. === //
function request(url,parameters){
AJAX(url,parameters,
function(data){
$j('#my_box').html(data);
}
);
}
// === Function: sendForm(); Sends the form and updates the page. === //
function sendForm(id,url){
var form = $j("form#"+id).serialize();
AJAX(url,form,function(data){$j("#my_box").html(data);});
}
// === Below are items that are activated once the DOM is loaded. === //
var curHashVal = window.location.hash;
document.observe("dom:loaded",function(){
$j("#loader").ajaxStart(function(){
loading();
}).ajaxStop(function(){
loaded();
});
if(window.location.hash.length > 1) content(curHashVal.substr(1));
new PeriodicalExecuter(function() {
if(curHashVal != window.location.hash){
content(window.location.hash.substr(1));
curHashVal = window.location.hash;
}
},.15);
});