473,385 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Page switcher

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

Mar 8 '06 #1
9 1658
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
Mar 8 '06 #2
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
Mar 8 '06 #3
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

Mar 8 '06 #4
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
Mar 8 '06 #5
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

Mar 8 '06 #6
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

Mar 8 '06 #7
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
Mar 8 '06 #8
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
Mar 8 '06 #9
JRS: In article <11**********************@e56g2000cwe.googlegroups .com>
, dated Tue, 7 Mar 2006 16:59:45 remote, seen in
news:comp.lang.javascript, Jason <ja*******@gmail.com> 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.
Mar 9 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Christo | last post by:
Hi all! (N00b meat here-- :) Anyway, the header of this message tells you what I am seeking. The audience for my site is the lowest level tech user (because my agency is a social service...
5
by: johnny | last post by:
hi all, I would like to know if the more and more websites offering the 3 font sizes option by style switching are just following a trend or have chose the best solution by an...
1
by: Frank J. Reashore | last post by:
Hello All, I am trying to download Dennis Bauer's ASP.net Version Switcher, however his web site is down. Does anyone know of an alternate location for this download? The original link was ...
10
by: Pete | last post by:
I have the following code: <built-in method close of file object at 0xb7cc76e0> The file "temp.html" is created, but it doesn't look like the page at www.python.org. I'm guessing there are...
0
by: Marcel Brekelmans | last post by:
Hello, I'm making an application, but sofar I can't get its icon to appear in the task switcher. I have created an iconfile with three icons in it: 16x16, 32x32, 48x48, 24bpp. I have assigned it...
4
by: james00 | last post by:
Switching Page Layouts!!! Does anyone have any idea how to create a script for Switching Page Layouts. I know how to create one for Style Sheet Switcher ...
2
by: Gary Brown | last post by:
Hi, How do you remove an icon from the task switcher menu? (The one you get with ALT-TAB.) I think I asked this before but never got an answer. Now I have another app that shows an icon for...
3
pezholio
by: pezholio | last post by:
Hi, I'm currently putting together a stylesheet switcher for a project I'm working on, it's a server side solution at the moment, and I'd like to AJAX it up and avoid page reloads. I'm using...
3
by: Dave Angel | last post by:
I have implemented the 'A list apart' styleswitcher which works great. I now have: - A permanent stylesheet - A normal contrast stylesheet - A high contrast stylesheet The switcher simply...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.