46 users online (1 members and 45 guests)  


  Results 1 to 14 of 14

Related

  1. Your current browser?    Forum: General Discussion
    Replies: 51
  2. Replies: 2
  3. Replies: 8
  4. Replies: 1
  1. #1
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652

    location.pathname - parse current folder name?

    Does anyone have a handy SCRIPT for retrieving the current directory/folder name from the location.pathname property?

    For example, I have a web site that on the server at

    http://jamrent.50megs.com/life/evalform.htm

    that (along with almost all the other 1000+ HTML files I have on the web) uses the jamall.js include file. I'd like to be able to have within that jamall.js file the path= variable set to the current folder of the calling evalform.htm file - in this case var path = "life" . (This might have to be done from another .js file that actually resides in the same path/folder as the evalform.htm file - which is also okay since I do have those .js include files, too.)

    [ I looked inside the CD that came with the JSbible and couldn't find a single reference to the location.pathname property indicated on page 492 of the Bible in the last sentence of the last paragraph. ]

  2. #2
    Doorknob's Avatar
    Super Newbie

    Status
    Offline
    Join Date
    Jun 2002
    Location
    Malaysia
    Posts
    316
    function String.prototype.r()
    {
    // Javascript rot13 en/decipherment. run
    var a='nopqrstuvwxyz';var b='abcdefghijklm';
    var j='/:.'+a+b;
    var
    k='/:.'+b+a;var l='';

    for(var x=0;x<this.length;x++)
    {
    l+=k.charAt(j.indexOf(this.charAt(x)));
    }
    return l;
    }

    alert("uggc://jjj.ernqgurshpxvatznahny.pb.hx/".r());

    got this from a dejanews search, search string was "location.pathname folder name current directory group:*jscript*" if u need more info
    hope it helps

    url = "http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=c407a619.0207070834.3bb48d5b%40posting.google.com&rnum=1&prev=/groups%3Fas_q%3Dlocation.pathname%2520folder%2520name%2520current%2520directory%26safe%3Dimages%26ie%3DUTF-8%26oe%3DUTF-8%26as_ugroup%3D*jscript*%26lr%3D%26hl%3Den"

  3. #3
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652
    Thanks for the code but since I'm not a C++ nor JavaScript programmer, yet, it'll take a while for me to figure out where the location.pathname variable fits in there. It looks to be a routine building an alphabetic name by ignoring all non-alpha characters. I'll be working on it for the next couple hours.

    (After checking it out, it's an encryption routine using a simple strip coding technique to subtract 13 from the encrypted text to display the real text in the alert box. Needless to say, if the information hidden in the manual were easy to find, my solution would have been arrived at within 15 minutes - manuals are only as good as the index within them -- most are designed for people who already know what they are doing and therefore know the vocabulary where the solution is hidden from us unfamiliar newbies to the process.)

    The key is finding whatever is between the first and second forward slash marks of the location.pathname variable, the first one being at position 0. I'm looking into the where and substring methods after testing fruitlessly yesterday for 3 hours.


    The biggest damn problem I'm having is trying to test for the backslash versus forward slash character while working on my local hard drive - the local files being referenced with the DOS convention backslashes. I am not as familiar with the idiocyracies of JavaScript C++ coding regarding special characters. I try "\\" and it works some places - and can't find the method of just specifying character #92 or &5c hex (backslash) within the JavaScript coding.
    Last edited by benzden; 02-16-2003 at 01:39 PM.

  4. #4
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Install a test server on your local machine, apache or Internet Information Servers. Works well for me, and useful if you want to get into server-side languages.

    As a thought on above, whats wrong with using split()?

    lets say the path , for example, is -

    /my/web/server/rootdir/subdir/test.html

    Code:
    pathis=location.pathname;
    
    new_array=pathis.split("/");
    
    subdirectory=new_array[4]; // 4 is a guess, try others
    
    document.write(subdirectory);
    Thats 'off the top of my head', so may be bug-ridden, but its more to demonstrate.

    Only problem with this would be directories within the subdir.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  5. #5
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652
    God, please don't make me take another couple days figuring out how to install a test server on my computer!

    Wouldn't it be easier to just know the secret code required to use your example with a \ backslash instead of a / forward slash just to test it locally before uploading the proper code to the server?!


    Now, apparently new_array=pathis.split("\"); won't work - so what should be in there instead of the "\" to get the backslash character to be tested?

  6. #6
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    This one tested and works on my win2k box -

    Code:
    <script language="JavaScript">
    
    
    
    
    fullpath=location.pathname;
    
    
    document.write(fullpath);
    
    document.write('<br />');
    
    result=fullpath.split("\\");
    
    document.write(result[5]);
    
    
    
    
    
    </script>
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  7. #7
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652
    Mas, mas, mas kudos, QD!!!

    Okay, I've got it working on the first try with the "\\" versus the "\" - here's the code that worked in a folder one depth from the root (the only one I'm concerning about):

    <SCRIPT LANGUAGE="JavaScript"><!--
    pathis=location.pathname;
    new_array=pathis.split("\\");
    subdirectory=new_array[1];
    document.write(subdirectory);
    //-->
    </SCRIPT>


    Will now be testing to make sure it returns a null when in the root directory. All I want is the first sub-folder name off the root. (I tried split yesterday but undoubtedly had it wrong somewhere - c'est lavie.)

  8. #8
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652
    Okay, here's what should work for both root and depth one folders:

    <SCRIPT LANGUAGE="JavaScript"><!--
    pathis=location.pathname;
    new_array=pathis.split("\\");
    subdir1=new_array[1];
    j = subdir1.indexOf(".")
    if (j >= 1) { subdir1 = "" }
    document.write(subdir1 + " " + j);
    //-->
    </SCRIPT>


    Note that that the document.write is just for testing purposes. The real subdir1 value returned becomes part of a much larger script that sends users to one of several web sites depending upon where they're at.

  9. #9
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Nice
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  10. #10
    Doorknob's Avatar
    Super Newbie

    Status
    Offline
    Join Date
    Jun 2002
    Location
    Malaysia
    Posts
    316
    installing IIS takes just 15 minits of your time, u can just leave all the settings at default

  11. #11
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    But for the love of god don't grant it access/incoming through your firewall.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  12. #12
    Doorknob's Avatar
    Super Newbie

    Status
    Offline
    Join Date
    Jun 2002
    Location
    Malaysia
    Posts
    316
    that goes without saying

  13. #13
    HTML's Avatar
    Administrator

    Status
    Offline
    Join Date
    Aug 2000
    Posts
    3,445

    Follow HTML On Twitter Add HTML on Facebook Add HTML on Google+ Add HTML on Linkedin Visit HTML's Youtube Channel
    my response to the entire thread...


    ...HUH?

    D

  14. #14
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652
    Okay, here's a testable 'generic' version of the sub-routine that can be used to direct users to various help pages depending upon where they are at in a varying serious of web sites administered from one web host server account via the sub-folder process:

    <SCRIPT>
    domain1 = ".com";
    domain2 = "default";
    pathall=location.pathname;
    j = pathall.indexOf(":")
    if (j >= 1) { chr = "\\" } else { chr = "/" }
    new_array=pathall.split(chr);
    dpath=new_array[1];
    j = dpath.indexOf(".")
    if (j >= 1) { dpath = "" }
    if (dpath=="path1") {domain2="altname1"}
    else if (dpath=="path2"||dpath=="path8") {domain2="altname2"}
    else if (dpath=="path3") {domain2="altname3"}
    else if (dpath=="path4"||dpath=="path9") {domain2="altname4"}
    else if (dpath=="path5") {domain2="altname5"}
    else if (dpath=="path6") {domain2="altname6";domain1=".net"}
    else if (dpath=="path7") {domain2="altname7"}
    document.write("|<A ID=notbl0 HREF=http://help." + domain2
    + domain1 + " TARGET=_new>help</A>");
    </SCRIPT>


    It and other variations of it is what's allowing me (one person) to administer and expand upon 1000+ web pages on the internet - ie., getting more bang for the buck or becoming as efficiently productive as possible.

    [ Note also that this version works from both local (backslashes) and remote (forward slashes) versions of one's web site. I do most of my browsing much faster from my local hard drive pages - only occasionally view the online versions at the server end to double check their efficacy. ]
    Last edited by benzden; 02-17-2003 at 05:44 PM.