I have a page that uses a template with some simple Javascript that changes the look of certain items on the page. When I am logged in, it all works as it should. When I am not logged in, nothing is displayed. The entire body of the page is empty. I can still see the Javascript in the header though. I see no error reports in the Apache logs or anywhere else. Does anyone know what’s going on?
We’re using Apache 2.2, MySQL 5.0 and PHP 5.3.1 on Microsoft Windows Server 2003. But I get the same problem on my local machine, which runs Windows 7 (and MySQL 5.1).
This is the Javascript:
window.onload = function() {
makeExpandable(2);
}
function makeExpandable(imgsInRow) {
var imageDiv = document.getElementById("expandable-img-div");
var divChildren = collectionToArray(imageDiv.getElementsByTagName("*"));
var counter = 0;
var parArr = new Array();
for each(var child in divChildren) {
if (child.nodeType == 1) {
if (child.tagName.indexOf("img") == 0 || child.tagName.indexOf("IMG") == 0) {
counter++;
// stick image element into its own special div
var newDiv = document.createElement("div");
newDiv.setAttribute("class", "expandable");
newDiv.appendChild(child);
imageDiv.appendChild(newDiv);
// insert a dividing bar if maximum number of images on a single line has been reached
if (counter > 0 && counter % imgsInRow == 0) {
var divider = document.createElement("div");
divider.setAttribute("style", "clear: right; height: 10px;");
divider.innerHTML = " ";
imageDiv.appendChild(divider);
}
}
}
}
// get rid of paragraph tags which are empty now
// TODO: they may not be empty!! User may have added a paragraph with text in it.
var parArr = collectionToArray(imageDiv.getElementsByTagName("p"));
for each(var par in parArr) {
imageDiv.removeChild(par);
}
}
function collectionToArray(col)
{
a = new Array();
for (i=0; i<col.length; i++) {
a[a.length] = col[i];
}
return a;
}
And this is how it’s put into the header part of the template:
<script src="[(base_url)]assets/js/expander.js" type="text/javascript">