Some time ago I asked a question about the same issue, @BenAlabaster explained it thoroughly in his answer, I guess I am still missing a piece of logic here.
I tried to call functions that are assigned to variables like I've shown below, in the last function.
Well it didn't work. Assuming it happened because the variable functionThree
is outside the addOnload()
function, I tried to move it inside and the browser just crashed.
addOnload(functionOne);
addOnload(functionTwo);
addOnload(functionThree);
function addOnload(newFunction){
oldOnload = window.onload;
if(typeof oldOnload == "function"){
window.onload = function(){
if(oldOnload){
oldOnload();
}
newFunction(); //This is what I missed, and that's what caused the crash.
}
}
else{
window.onload = newFunction;
}
}
function functionOne(){
alert("This is the first function on this page!");
}
function functionTwo(){
alert("This is the second function on this page!");
}
functionThree = function(){
alert("This is the third function on this page!");
}