I'm trying to run a function at pageload:
<script type="text/javascript" src="functions.js"></script>
<body onload="startUp();">
The problem is startUp() isn't running, nor is anything else that I try to refer to in my JS file. I am certain that the link to the JS file is correct; and even if it weren't, I even tried pasting all of functions.js right into the page header--still nothing. This is the content of functions.js:
function startUp() {
document.write("running"); //for debugging
alert("running"); //for debugging
stretchAbdomen();
if (defaultStyle()) {
setStyleCookie(1, false);
}
else { //if mobilestyle
setStyleCookie(0, false);
if (!window.location.hash) {
window.location.hash = "#mobilearea";
}
}
}
function stretchAbdomen() {
var bodyheight = getbodyheight();
var abdomen = document.getElementById('abdomen');
if (window.innerHeight > bodyheight) {
var currentpaddingstring = window.getComputedStyle(abdomen, null).getPropertyValue('padding-bottom');
var currentpadding = Number(currentpaddingstring.substring(0, currentpaddingstring.length - 2)); //-2 removes "px" from string
abdomen.style.paddingBottom = (((window.innerHeight - bodyheight) + currentpadding) + "px";
}
}
function getbodyheight() {
var body = document.body,
html = document.documentElement;
return Math.min( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
}
/*** BELOW HERE SHOULD NOT BE RELEVANT FOR THE QUESTION ***/
window.onresize = resetStyleCookie;
function defaultStyle() {
if (window.getComputedStyle(document.getElementById('mobilearea')).getPropertyValue('width') == "1px")
return true;
else return false;
}
function resetStyleCookie() {
document.cookie = "stylecookie=" + "; expires=Thu, 01 Jan 1970 00:00:01 GMT;";
setStyleCookie(defaultStyle() ? 1 : 0, true); //forcereset because otherwise it wasn't working on subpages
}
function setStyleCookie(number, forcereset) {
if (document.cookie.indexOf("stylecookie") == -1 || forcereset) {
var now = new Date();
var time = now.getTime();
time += 3600 * 150000;
now.setTime(time);
document.cookie = "stylecookie=" + number + "; expires=" + now.toGMTString() + "; path=/";
}
}
I have to assume that there's some compile-time problem in functions.js, but my debugging tools show no errors, nor can I find anything myself. The call to startUp() simply does nothing, even when I don't rely on the onload event to call it. Thanks for any insight!