www.webdeveloper.com
Results 1 to 7 of 7

Thread: Like to same filename in different directory

Hybrid View

  1. #1
    Join Date
    Mar 2010
    Posts
    11

    Like to same filename in different directory

    Did 15 mins of Google searching, nothing useful. As the thread location suggests, I am working in HTML. No switching for me at this point in time.

    So here's what I want. I have a Dutch section (/nl/) and an English section (/en/)of my website. In my navigation bar I have 2 flags representing each language. Is it possible to link the user to the same file but in a different directory if they click one of the flags? So if they are on /nl/about.html, and they click on the English flag, they are linked to /en/about.html.

    By the way I am using dwt's (Dreamweaver Templates), so that's why I would want one piece of code and be done with it.


    Thanks in advance!

  2. #2
    Join Date
    Mar 2010
    Posts
    2
    Not really sure what the problem here is, it wouldn't be linking to the 'same' file if its in a different directory, you'd have to make two copies of the file and place one in /nl/ and one in /en/.

  3. #3
    Join Date
    Mar 2010
    Posts
    2,803
    I found this useful script on the www which returns the basename of your web page's current url.

    If you set the suffix argument to an empty string you get the full base name including filename extension.

    If you set a suffix like '.htm', you get the basename minus the suffix, assuming your url ends in .htm

    You then only need to append it to the directory path to the alternate language folder on your site and then redirect your browser using JS to the new url.

    I'm not a Dreamweaver user so I don't know how to integrate this script into your code. Maybe someone else can help or offer a better solution.


    Code:
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    <script type="text/javascript">
    function basename(path, suffix) {
        // Returns the filename component of the path  
        // 
        // version: 910.820
        // discuss at: http://phpjs.org/functions/basename    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
        // +   improved by: Ash Searle (http://hexmen.com/blog/)
        // +   improved by: Lincoln Ramsay
        // +   improved by: djmix
        // *     example 1: basename('/www/site/home.htm', '.htm');    // *     returns 1: 'home'
        // *     example 2: basename('ecra.php?p=1');
        // *     returns 2: 'ecra.php?p=1'
        var b = path.replace(/^.*[\/\\]/g, '');
            if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
            b = b.substr(0, b.length-suffix.length);
        }
        
        //return b;
        
        alert(b);
    }
    </script>
    </head>
    
    <body onload="basename(window.location.href,'');">
     
    <h1>hello world</h1>
     
    </body>
    </html>
    Last edited by tirna; 03-21-2010 at 12:14 AM.

  4. #4
    Join Date
    Mar 2010
    Posts
    11
    Quote Originally Posted by tirna View Post
    I found this useful script on the www which returns the basename of your web page's current url.

    If you set the suffix argument to an empty string you get the full base name including filename extension.

    If you set a suffix like '.htm', you get the basename minus the suffix, assuming your url ends in .htm

    You then only need to append it to the directory path to the alternate language folder on your site and then redirect your browser using JS to the new url.

    I'm not a Dreamweaver user so I don't know how to integrate this script into your code. Maybe someone else can help or offer a better solution.


    Thanks a lot for the effort, it's a pity that my Javascript skills suck. I think I know for about 1/4 what that all means. Maybe less even...

    If someone would like to help me out it would be awesome, but I guess I'm not really asking for it, since a solution has been given, and if I start learning Javascript now, I could do it. The thing is, I would love to learn Javascript, but I would also love to have my website up and running in about a week.

    So if anyone wants to help me with this it would be freakin great.

  5. #5
    Join Date
    Mar 2010
    Posts
    11
    Quote Originally Posted by Kodias View Post
    Not really sure what the problem here is, it wouldn't be linking to the 'same' file if its in a different directory, you'd have to make two copies of the file and place one in /nl/ and one in /en/.
    I should have been more clear. I want it to link to a file with the same NAME as the current file, but in a different directory.

  6. #6
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    At least 98% of internet users' DNA is identical to that of chimpanzees

  7. #7
    Join Date
    Mar 2010
    Posts
    11
    Oops as I was going through my tabs I noticed I spelled "Like" instead of "Link" I don't think I have the privilege to change this, can someone do this please? That way other people can find it too

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles