Page switcher

Discussion in 'Javascript' started by Jason, Mar 8, 2006.

  1. Jason

    Jason Guest

    I have translated my website into Japanese, so if someone visits this
    page in English:

    http://dheera.net/jason/about/interests/music/index.html

    I want them to be able to click on word 日本語 at the bottom to go
    to the corresponding page in Japanese, which would be:

    http://dheera.net/jason/ja/about/interests/music/index.html

    As you can see the only difference is that the Japanese page is in the
    directory 'ja/'.

    Is there any way, using Javascript that I can dynamically retrieve the
    current url and add 'ja/' to it?

    Jason
     
    Jason, Mar 8, 2006
    #1
    1. Advertising

  2. Jason wrote:

    > Is there any way, using Javascript that I can dynamically retrieve the
    > current url and add 'ja/' to it?


    There is, but since you mean client-side JavaScript: don't.
    Navigation should be possible without client-side script support.
    Use server-side scripting instead, preferably PHP, ASP (which can
    use server-side JScript), or Perl.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Mar 8, 2006
    #2
    1. Advertising

  3. Jason

    RobG Guest

    Jason wrote:
    > I have translated my website into Japanese, so if someone visits this
    > page in English:
    >
    > http://dheera.net/jason/about/interests/music/index.html
    >
    > I want them to be able to click on word 日本語 at the bottom to go
    > to the corresponding page in Japanese, which would be:
    >
    > http://dheera.net/jason/ja/about/interests/music/index.html
    >
    > As you can see the only difference is that the Japanese page is in the
    > directory 'ja/'.
    >
    > Is there any way, using Javascript that I can dynamically retrieve the
    > current url and add 'ja/' to it?


    You seek the location object:

    <URL:http://developer.mozilla.org/en/docs/DOM:window.location>


    But why not just hard code the link? JavaScript is intended to enhance
    browsing, things shouldn't depend on it being available or supporting
    the features you've used.



    --
    Rob
     
    RobG, Mar 8, 2006
    #3
  4. Jason

    Jason Guest

    I can't hard code it because I'm using a program called rapidweaver.
    That section of the hompage is repeated, it can't be made unique. Also
    if it were possible to hard code and I changed my mind it future that
    would be a lot of work to change a small thing.

    Thanks,

    Jason
     
    Jason, Mar 8, 2006
    #4
  5. Jason wrote:

    > I can't hard code it because I'm using a program called rapidweaver.


    ,-<URL:http://www.apple.com/downloads/macosx/internet_utilities/rapidweaver.html>
    |
    | About RapidWeaver
    | A next-generation web design application to help you create professional
    | looking websites in minutes. No knowledge of complex code is required,
    | RapidWeaver will take care of all that for you. Makes it easy for everyone
    | to publish photos, movies and blogs online instantly. If you’re thinking
    | about starting a blog or website, RapidWeaver is the perfect choice.

    Reads like a recipe for disaster.

    > That section of the hompage is repeated, it can't be made unique. Also
    > if it were possible to hard code and I changed my mind it future that
    > would be a lot of work to change a small thing.


    If you used server-side scripting, there was no problem with that, and users
    could navigate without client-side script support. By hard-coding it was
    not meant that all the code has to be completely static.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Mar 8, 2006
    #5
  6. Jason

    Jason Guest

    Jason, Mar 8, 2006
    #6
  7. Jason

    Jason Guest

    Jason, Mar 8, 2006
    #7
  8. Jason wrote:

    > Looks like I got it working:
    >
    > http://dheera.net/jason/photos/index.html


    Unfortunately, that only seems to be so.

    > Click on 日本語 at the bottom.
    >
    > Do you guys think the code is efficient?


    First of all, since I do not have a Mac, I have taken the time to watch all
    three screencasts about RapidWeaver closely last night. I must say the
    things you can do with it are impressive indeed, however the way it is done
    is not. As I expected, it is basically a point-and-click application:
    unless you select the "HTML Code" template for your new Website (which will
    get you at least a HTML editor with syntax highlighting and some code
    templates), you will never see a single piece of its code before you
    publish it. I consider that to be a _Bad_ Thing, since I am convinced
    (from personal experience) that understanding Web authoring comes from
    understanding of the underlying concepts, including the used markup,
    formatting, and programming languages. What I observed on your new Website
    merely justifies this opinion.

    The script you use is completely unnecessary, since nothing is generated
    dynamically here -- it is but RapidWeaver which creates the illusion of
    that. In the end, your documents are all static. And you are not even
    referring to the "subpage" of the other language but always to the
    homepage. However, AIUI, it is possible to detach each document ("page")
    from the global Website layout, hence it should be possible to have a
    link to the "subpage" of the other language on each "subpage", without
    introducing a dependency on client-side scripting at all and thereby
    making navigation impossible without (enabled) support for it. The same
    goes for the `Launch in Google Maps' "links" in your Art/Google Maps
    section, for example.

    As was said before, `javascript:' is evil[tm]. Search the archives for
    "pseudo-protocol".

    As for the rest of "your" code:

    - You serve XHTML as text/html, which is error-prone:
    <URL:http://hixie.ch/advocacy/xhtml>

    - Internet Explorer does not support XHTML, and you do not need XHTML here.
    HTML 4.01 Strict/Transitional suffices and is _not less_ standards
    compliant than XHTML (I am emphasizing that here because RapidWeaver
    marketing emphasizes that the code generated by their tool would be
    standards compliant).

    - XHTML 1.0 _Transitional_ is (usually) a contradiction in itself.
    (Either you want well-formed Valid markup, dividing markup and formatting,
    or you want a tag soup with presentational elements and attributes.)

    - You have made a hyperlink out of your first-level heading, but users
    do not know about that (before they hover over/tab to it) because it
    looks like the rest of your text. Users expect textual hyperlinks to
    be underlined or at least in a different color by default, probably
    except of hyperlinks in navigation sections of a document.

    - Black on dark gray is hardly a good color combination, especially for
    a (first-level) heading. More contrast, and a little bit more color,
    please.

    - You use `br' elements where there is no line-break intended.

    - Your script resource (javascript.js) contains `<!--' and `//-->' outside
    of literals which is utter nonsense, especially in an XHTML context.
    (Search the archives.) Remove that.

    - if (!document.getElementsByTagName) return;

    does not qualify as feature test for the method to be _called_.
    Search the archives for "isMethodType".

    - for (var i=0; i<anchors.length; i++) {

    is inefficient compared to

    for (var i = anchors.length; i--;) {

    - The whole `anchors-and-if (anchor.getAttribute("href") ...' thing
    is unnecessary, W3C DOM Level 2 HTML defines the `links' collection
    as property of the `document' (HTMLDocument) object, which is
    supported since NN 2.0, IE 3.02/4.0(CE; according to MSDN Library),
    Opera 6 (at least), and by KHTML-based UAs (Konqueror, Safari etc.).

    - Element::getAttribute() should be avoided if possible; its implementations
    are known to be buggy, and the value it returns is not "live". There are
    attribute properties in the HTML DOM for this, also specified in W3C DOM
    Level 2 HTML:

    for (var links = document.links, i = links.length; i--;)
    {
    var anchor = links;
    if (anchor.rel.toLowerCase() == "external")
    {
    anchor.target = "_blank";
    }
    }

    - The above was just for the sake of completeness. _Do not_ try to impose
    new windows/tabs on users with target="_blank", even though the link is
    "external". Remove externalLinks(), or modify it so that "external"
    links are marked instead.

    - `document.location' is deprecated long since. W3C DOM Level 2 HTML
    calls for `document.URL' -- which is in fact supported as a string
    property since NN 2.0, IE 4.0 (all platforms, according to MSDN
    Library), Opera 6.0 (at least), and by KHTML-based UAs, fortunately :)

    - All your variables (whereas some of them are unnecessary) are in fact
    properties of the global object, or of the object before it in the scope
    chain, because you do not declare them with `var'. This is considered
    error-prone, search the archives.

    - Your script code lacks proper indentation.


    Please quote the minimum of what you are replying to:

    <URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1Post>
    <URL:http://www.safalra.com/special/googlegroupsreply/>


    HTH

    PointedEars
     
    Thomas 'PointedEars' Lahn, Mar 8, 2006
    #8
  9. Thomas 'PointedEars' Lahn wrote:

    > The script you use is completely unnecessary, since nothing is generated
    > dynamically here -- it is but RapidWeaver which creates the illusion of
    > that. In the end, your documents are all static. And you are not even
    > referring to the "subpage" of the other language but always to the
    > homepage. However, AIUI, it is possible to detach each document ("page")
    > from the global Website layout [in RapidWeaver], hence it should be
    > possible to have a link to the "subpage" of the other language on each
    > "subpage", without introducing a dependency on client-side scripting at

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    > all and thereby making navigation impossible without (enabled) support

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    > for it. The same goes for the `Launch in Google Maps' "links" in your

    ^^^^^^^
    > Art/Google Maps section, for example.


    The above is confusing. Should have been either

    ... without introducing a dependency on client-side scripting and
    thereby making navigation impossible without (enabled) support for
    it at all ...

    or

    ... without introducing a dependency on client-side scripting at all,
    and thereby making navigation possible without (enabled) support for
    it ...

    (But maybe you already got the idea ;-))


    PointedEars
     
    Thomas 'PointedEars' Lahn, Mar 8, 2006
    #9
  10. JRS: In article <>
    , dated Tue, 7 Mar 2006 16:59:45 remote, seen in
    news:comp.lang.javascript, Jason <> posted :
    >Ok guys, I've fooled around with the javascript a bit:
    >
    >http://dheera.net/jason/index2.html
    >
    >But I can only achieve this:
    >
    >http://dheera.net/ja/jason/index2.html
    >
    >As you can see the 'ja/' should be after 'jason/' not before it. Is
    >there any way to use a '.pos' to achieve that or perhaps an array or
    >something?



    St = "http://dheera.net/jason/index2.html"

    St = St.replace("/jason/", "jason/ja/")

    // result : http://dheera.netjason/ja/index2.html

    You might as well use client-side javascript for the job, if you are
    already committed to need client-side javascript (either /in toto/ or
    for the footer). Additionally, if you're using javascript at all, you
    should know how to code such substitutions, with and without RegExps.

    Alternatively,

    St = St.split("/") ; St[3] += "/ja" ; St = St.join("/")

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
    <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr John Stockton, Mar 9, 2006
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Frank J. Reashore

    ASP.net Version Switcher

    Frank J. Reashore, Aug 1, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    408
    Craig Deelsnyder
    Aug 7, 2004
  2. Hardeep Rakhra
    Replies:
    8
    Views:
    644
    Hardeep Rakhra
    Jan 15, 2004
  3. Hardeep Rakhra
    Replies:
    11
    Views:
    594
    Jeffrey Silverman
    Jan 16, 2004
  4. Tom Cloyd

    CSS switcher in Ruby?

    Tom Cloyd, Oct 5, 2005, in forum: Ruby
    Replies:
    10
    Views:
    210
    Adam Van Den Hoven
    Oct 5, 2005
  5. Kerberos

    Nice links switcher - How is it called?

    Kerberos, Jan 10, 2005, in forum: Javascript
    Replies:
    1
    Views:
    91
    Robert
    Jan 12, 2005
Loading...

Share This Page