SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Enthusiast ttcf's Avatar
    Join Date
    Nov 2001
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript problem

    Please can you have a quick look at http://www.toytraincollectorsfairs.com

    if you click on the dates page you will see that there is a javascript resent backpages thing (like at the top of these boards) please could somebody tell me how to set it so that the pages have names i.e Dates, instead of Date.htm


    thankyou


    TTCF

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The script that the page uses just breaks down the string. At the end, it uses a couple of snippets that remove and anchors and query strings.
    Code:
    // remove anchors
    if (href.indexOf('#') != -1) {
    href = href.substring(0, href.indexOf('#'));
    }
    
    // remove query string
    if (href.indexOf('?') != -1) {
    href = href.substring(0, href.indexOf('?'));
    }
    Now, you could just add another one to take care of the .htm
    Code:
    // remove '.htm'
    if (href.indexOf('.htm') != -1) {
    href = href.substring(0, href.indexOf('.htm'));
    }
    Personally, I prefer the regular expression method for replacing:
    Code:
    href = href.replace(/.htm/g,"");
    That should do it
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Enthusiast ttcf's Avatar
    Join Date
    Nov 2001
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thanks

    thanks, but as you can see on this page the original page has the whole name i.e http://www24.brinkster.com how can i get rid of this to.

    so it ends up looking like this

    Home/Dates


    code:


    <!-- Begin
    //author: Jake Fairhead
    var path = "";
    var href = window.location.href;
    var start = href.substring(0, href.indexOf('//') + 2);
    var pos = href.indexOf('//');
    href = href.substring(pos + 2, href.length);
    pos = href.indexOf('/');
    path = start + "";

    document.write(start);
    while (pos != -1) {
    var name = href.substring(0, pos);
    path += name + "/";
    document.write("<a href=\"" + path + "\">" + name + "</a>");
    document.write("<");
    href = href.substring(pos + 1, href.length);
    pos = href.indexOf('/');
    }

    // remove anchors
    if (href.indexOf('#') != -1) {
    href = href.substring(0, href.indexOf('#'));
    }

    // remove query string
    if (href.indexOf('?') != -1) {
    href = href.substring(0, href.indexOf('?'));
    }

    // remove '.htm'
    if (href.indexOf('.htm') != -1) {
    href = href.substring(0, href.indexOf('.htm'));
    }
    document.write("<a href=\"" + path + href + "\">" + href + "</a>");

    // End -->
    Last edited by ttcf; Jul 20, 2002 at 02:47.

  4. #4
    SitePoint Enthusiast ttcf's Avatar
    Join Date
    Nov 2001
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    code

    if anyone knows a better code than this one then please let me know


    thankyou

    TTCF

  5. #5
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought of a slightly better method for removing the '.htm' Because that assumes that the file is HTML, it won't work for anything else.
    Code:
    // remove document suffix
    if (href.lastIndexOf('.') != -1) { 
    href = href.substring(0, href.lastIndexOf('.')); 
    }
    or the regular expression equivalent
    Code:
    href = href.replace(/(\.{1}\d{1,})$/,"");
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  6. #6
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    problem: people use .'s in names.

    You could use a greedy regex to solve that for the last one.


    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---


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
  •