Results 1 to 3 of 3

Thread: Link to a parent directory

  1. #1
    Join Date
    Jul 2008
    Posts
    9
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Link to a parent directory

    Hello,

    I am after a script that can be put on a normal a href link that will work across all pages within my (large) web site. I want it to search for a page of the same name but within a parent directory and then take the user to it.

    Example:

    So by clicking on a link here "folder-name/translation-example.htm" will take the user back a directory to here "translation-example.htm". I want this to be automated though so I don't have to edit the links on each page of my site.

    Does this even exist? Does anybody know of a script that can help?

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The path you need is "../[pagename]".

    To get [pagename], you will need to parse the current url. Doing it with Javascript will require that users have Javascript and might be difficult, because parsing URLs with Javascript can get a little complex.
    Using PHP (or another server side language) would be easier, though that would require PHP is installed on your server (and the users would NOT need to have it).

    But this also means that all of these links would need to be dynamically written with Javascript/PHP, so it would not save you that much time (but might, depending on the situation).

    Which language would you like to use? From there you just need to find the current filename-- get the full url and cut it at the last slash.


    I don't know how complex your project is, but unless it is very large and automatically generated already, it seems like this would be easier just to type out each time. But you can certainly use Javascript or PHP if you'd like...
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. The Following User Says Thank You to djr33 For This Useful Post:

    egr103 (01-19-2010)

  4. #3
    Join Date
    Jul 2008
    Posts
    9
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    So there is no way of writing a generic piece of code that will parse the current page name and go find it within another directory? I will have to change the URL manually anyway but within PHP or Javascript?

    Bummer!

    I might as well avoid the excess code then and just do it all manually within each individual page.

    Shame it can't be done though it would have saved so much time!

    @djr33 thanks though mate!

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
  •