Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Page switcher

Reply
Thread Tools

Page switcher

 
 
Jason
Guest
Posts: n/a
 
      03-08-2006
I have translated my website into Japanese, so if someone visits this
page in English:

http://dheera.net/jason/about/intere...sic/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/int...sic/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

 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      03-08-2006
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
 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      03-08-2006
Jason wrote:
> I have translated my website into Japanese, so if someone visits this
> page in English:
>
> http://dheera.net/jason/about/intere...sic/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/int...sic/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
 
Reply With Quote
 
Jason
Guest
Posts: n/a
 
      03-08-2006
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

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      03-08-2006
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
 
Reply With Quote
 
Jason
Guest
Posts: n/a
 
      03-08-2006
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?

Thanks,

Jason

 
Reply With Quote
 
Jason
Guest
Posts: n/a
 
      03-08-2006
Looks like I got it working:

http://dheera.net/jason/photos/index.html

Click on 日本語 at the bottom.

Do you guys think the code is efficient?

Many thanks,

Jason

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      03-08-2006
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[i];
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
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      03-08-2006
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
 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      03-09-2006
JRS: In article <(E-Mail Removed) .com>
, dated Tue, 7 Mar 2006 16:59:45 remote, seen in
news:comp.lang.javascript, Jason <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recent switcher : Filter question Gary Digital Photography 4 05-31-2006 02:11 AM
where can I find a connection switcher FireBrick Wireless Networking 3 08-27-2004 02:26 PM
ASP.net Version Switcher Frank J. Reashore ASP .Net 1 08-07-2004 07:09 PM
alistaprtstyle switcher, works but kills my default style :O( Hardeep Rakhra HTML 11 01-16-2004 04:50 PM
Javascript Style Switcher that remebers current site style in use Hardeep Rakhra HTML 8 01-15-2004 08:00 PM



Advertisments