SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    retrieving folder and file name from top.location

    I'm trying to get the folder-name and file-name from the top.location.

    I started with this
    Code:
    doctitle="";
    starter=top.location.href.indexOf("url.co.uk/");
    topURL=top.location.href
    endoffind=top.location.href.indexOf(".html");
    startoffind=starter+10
    for(i=startoffind;i<endoffind;i++){ doctitle+=(topURL.charAt(i)) }
    alert(doctitle);
    It can give me a file-name minus the ".html", but its getting difficult to go further....eg splitting "url.co.uk/file/folder/doc.html"

    Any regexp experts that can help their efforts will be greatly appreciated
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  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)
    Uhhh, something like this?
    Code:
    var myUrl = "url.co.uk/file/folder/doc.html";
    var results = myUrl.match( /^(?:url\.co\.uk\/)([^\/]+)(?:\/)([^\/]+)(?:\/)([^\.]+)(?:\.html)$/ );
    alert( results[1] + "\n" + results[2] + "\n" + results[3] );
    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
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    that works....

    Thanks Beetle, that works, but I want to use top.location, so I need to take it from the start of url.co.uk, ignoring whether online or not.

    Also, how would I ask....
    if doc="drum"+(any number)
    only to trigger when a number is found following the word "drum" but not if a word is found.

    I have a page called drumprice and I don't want the wrong functions to be called when "drum0.html" has been asked for. I used to use the indexOf(drum) command, but this would show 0 for both.
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  4. #4
    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)
    Code:
    var myUrl = top.location.href;
    var results = myUrl.match( /^(?:url\.co\.uk\/)([^\/]+)(?:\/)([^\/]+)(?:\/)([^\.]+)(?:\.html)$/ );
    var drumNum = results[3].match( /\d+/ );
    if ( Boolean( doc = drumNum[1] ) )
    {
        // number found and stored in 'doc'
    }
    else
    {
        // number not found
    }
    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





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
  •