SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Location
    Guelph Canada
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    It works on my local server not once I upload it.

    Hi

    I found some javascript on the web and inserted into my website on my localserver(localhost) and the breadcrumbs work just fine.

    I have an external javascript file called breadcrumbs.js

    When I upload it to my remote web server http.treanorhobbies.com/ It no longer
    recognizes it, but does leave a space under the main banner made by the CSS.

    Why would it work on localhost but not remote server?

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,445
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    works - doesn't work

    Without seeing any code, I would guess that it's either a wrong path, or a spelling error, maybe a case-sensitive issue.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Location
    Guelph Canada
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry about that: here it is

    HTML:
    Code:
    <div id="breadcrumbs">
    		<script type="text/javascript" src="breadcrumbs.js"></script>
    	</div>
    CSS for Breadcrumbs called mysite.css
    Code:
    #breadcrumbs {
    
    	height:50px;
    	width: 800px;
    	
    }
    Then my(actually someone else's) external javascript file called breadcrumbs.js
    Code:
    var homePage = "";
    
    /* The variable below controls the character(s) that the script places between
    the link levels. The default is set to be the > (greater than) HTML entity
    with a space on either side. Change this to whatever you want, but if the
    character has an HTML entity, be sure to use that. */
    
    var sepChars = " > ";
    
    /* In most cases, the value below should just be a / sign. Or, you can use the
    fully qualified http://www.yoursite.com address if you'd rather. Basically,
    it just tells the script what all the link addresses will start with. */
    
    var linkHome = "/";
    
    /* Leave the value below set to 'true' if you want the script to not list your
    index page name (index.html) at the end of the links path. The values 'true' or
    'false' should be used without quotes. */
    
    var hideIndex = true;
    
    /* Leave the value below set to 'true' if you want the script to convert any
    underscores in directory or names to spaces. For instance, it would convert
    "golive_actions" to "golive actions". The values 'true' or 'false' should be
    used without quotes. */
    
    var UToSpace = true;
    
    /* Leave the value below set to 'true' if you want the script to convert any dashes
    in directory or page names to spaces. For instance, it would convert "golive-actions"
    to "golive actions". The values 'true' or 'false' should be used without quotes. */
    
    var DToSpace = true;
    
    /* The variable below allows you to change the capitalization of the directory and
    pages names in your menu. The value should be a number between 0 and 3, without
    quotation marks. Options are as follows: 0 = no change; 1 = initial caps;
    2 = all upper case; 3 = all lower case */
    
    var changeCaps = 2;
    
    /* If set to true, the variable below will not display the file's extension for
    any file names displayed in the menu. Otherwise, set to false to show extensions.
    The values 'true' or 'false' should be used without quotes. */
    
    var hideExt = true;
    
    
    // build breadcrumb links...
    function MPJSBackLinks() {
    var linkHTML = '';
    var thisURL = window.location + '';
    var urlPair = thisURL.split('//');
    if (urlPair.length > 1) thisURL = urlPair[1];
    var dirArray = thisURL.split('/');
    var linkArray = dirArray.slice(1);
    var linkDir = '/';
    var currentPage = '';
    if (linkHome != '' && linkHome != '/') {
      var thisTest = linkHome.split('//');
      if (thisTest.length > 1) linkHome = thisTest[1];
      startArray = linkHome.split('/');
      var backCount = 0;
      for (var n=0; n<startArray.length; n++) {
        if (startArray[n] == '..') backCount++;
          else break;
        }
      if (backCount > 0) {
        var part1 = dirArray.slice(0, (dirArray.length - backCount - 1));
        var part2 = startArray.slice(backCount);
        startArray = part1.concat(part2);
        } else {
        var newStart = new Array(dirArray[0]);
        for (var n=1; n<startArray.length; n++) {
          var thisTest = (typeof dirArray[n] != "undefined") ? dirArray[n] : false;
          if (thisTest && thisTest == startArray[n]) newStart[n] = startArray[n];
            else break;
          }
        startArray = newStart;
        }
      if (startArray.length > 1) {
        var lastOne = startArray[startArray.length - 1];
        if (lastOne != '') {
          var thisTest = lastOne.split('.');
          if (thisTest.length > 1) startArray[startArray.length - 1] = '';
            else startArray[startArray.length] = '';
          }
        if (homePage == '') homePage = startArray[startArray.length-2];
        linkArray = dirArray.slice(startArray.length - 1);
        if (startArray[0] != '') startArray[0] = "http://"+startArray[0];
        linkDir = startArray.join('/');
        } else linkArray = dirArray.slice(1);
      } else {
      linkArray = dirArray.slice(1);
      if (homePage == '') homePage = dirArray[0];
      }
    var backTrack = 1;
    if (linkArray[linkArray.length - 1] != '') {
      var lastOne = linkArray[linkArray.length - 1];
      var testName = lastOne.split('.');
      if (testName[0] == 'index' || testName[0] == 'default') {
        backTrack = 2;
        currentPage = linkArray[linkArray.length - 2];
        } else if (hideExt) currentPage = testName[0]
        else currentPage = lastOne;
      } else {
      backTrack = 2;
      currentPage = linkArray[linkArray.length - 2];
      }
    var html = '';
    if (linkArray.length >= backTrack) {
      linkArray = linkArray.slice(0, linkArray.length - backTrack);
      var links = new Array();
      if (homePage != '') {
        homePage = MPBCParseText(homePage, UToSpace, DToSpace, changeCaps);
        links[links.length] = '<a href="'+linkDir+'">'+homePage+'</a>';
        }
      var baseDir = linkDir;
      for (var n=0; n<linkArray.length; n++) {
        baseDir += linkArray[n] + '/';
        var thisText = MPBCParseText(linkArray[n], UToSpace, DToSpace, changeCaps);
        links[links.length] = '<a href="'+baseDir+'">'+thisText+'</a>';
        }
      if (currentPage != '') links[links.length] = MPBCParseText(currentPage, UToSpace, DToSpace, changeCaps);
      html = '<div class="breadcrumbs">'+links.join(sepChars)+'<\/div>';
      }
    return html;
    }
    // parse string through text filters
    function MPBCParseText(thisText, UToSpace, DToSpace, changeCaps) {
    if (typeof thisText != "undefined" && thisText) {
      if (DToSpace) thisText = MPBCReplaceChar('-', ' ', thisText);
      if (UToSpace) thisText = MPBCReplaceChar('_', ' ', thisText);
      if (changeCaps) thisText = MPBCFixCaps(thisText, changeCaps);
      } else thisText = '';
    return thisText;
    }
    // find and replace single character in string...
    function MPBCReplaceChar(oldChar, newChar, thisString) {
    var newString = '';
    for (var n=0; n<thisString.length; n++) {
      newString += (thisString.charAt(n) == oldChar) ? newChar : thisString.charAt(n);
      }
    return newString;
    }
    // determine changes in capitalization...
    function MPBCFixCaps(thisString, changeCaps) {
    if (changeCaps == 1) thisString = MPBCUCWords(thisString);
      else if (changeCaps == 2) thisString = thisString.toUpperCase();
      else if (changeCaps == 3) thisString = thisString.toLowerCase();
    return thisString;
    }
    // capitalize the first letter of every word...
    function MPBCUCWords(thisString) {
    var thisArray = thisString.split(' ');
    var newString = '';
    for (var n=0; n<thisArray.length; n++) {
      var firstChar = thisArray[n].charAt(0).toUpperCase();
      var theRest = thisArray[n].substring(1, thisArray[n].length);
      newString += firstChar+theRest+' ';
      }
    return newString.substring(0, newString.length - 1);
    }
    document.write(MPJSBackLinks());

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,445
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    breadcrumbs script

    Odd. Using the code in the head section of a page works for me both on my local machine (Windows OS) and my server (LAMP).
    Are you certain you have the script tag's src attribute correct? That is, the path is correct and the spelling and case exactly match the path and name of the file.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Location
    Guelph Canada
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is what I have displayed on my Local Server in the firefox browser

    LOCALHOST > TREANORHOBBIES

    on my remote server there is nothing while my filestructure remains the same on my remote server as my local one.

    I'm new to javascript but I do know it's clientside so it shouldn't be the host that I'm using should it.....even though it is free. Everything else works like PHP.
    Code:
    <div id="header2">
    		<script type="text/javascript" src="breadcrumbs.js"></script>
    	</div>
    Everything seems right in terms of syntax my .js file is in the same folder as everything else.

    It doesn't make sense does it?

  6. #6
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Location
    Guelph Canada
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind I'm an idiot

    It won't display anything on the index page but the other pages obviously will.

    Issue solved......sorry for wasting your time.

    Scott


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •