ページロード時に関数を実行しようとしています:
<script type="text/javascript" src="functions.js"></script>
<body onload="startUp();">
問題は、startUp() が実行されていないことです。また、JS ファイルで参照しようとしているものも何もありません。JS ファイルへのリンクは正しいと確信しています。そうでない場合でも、すべての functions.js をページ ヘッダーに貼り付けてみましたが、まだ何もありません。これは 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=/";
}
}
functions.js にコンパイル時の問題があると想定する必要がありますが、私のデバッグ ツールはエラーを表示せず、自分で何かを見つけることもできません。startUp() の呼び出しは、onload イベントに依存して呼び出していない場合でも、何もしません。洞察をありがとう!