We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36875
    • 5 Posts
    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">
    
      • 36875
      • 5 Posts
      Turns out I had made non-validating html.

      Sorry for bothering you people smiley

      I am still curious though: why was this only a problem when I was not logged in? Isn’t one looking at the same page whether one is logged in or not?
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        If you mean "logged in as a Manager user", no, it isn’t the same page. Manager users get javascript and css code for the front-end editor.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org