Re: Moving to a modified URL
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Moving to a modified URL

From: alu <none@none.com>
Date: Fri Jul 01 2005 - 04:36:01 CEST

"alu" <none@none.com> wrote in

> "Normand Peladeau" <peladeau@see_our_domain.com> wrote
>
> > I would like to create a link on a web page that will call a script and
> jump
> > to an URL similar but slightly different than the current one. I am
doing
> > this to allow people to switch languages. For example, no matter where
> the
> > user is on my web site, if he clicks on the FRENCH button at the top, he
> > will be moved from:
> >
> > http://www.mydomain.com/apage.html
> >
> > to
> >
> > http://www.mydomain.com/fr/apage.html
> >
> > On this French version of the web page, if he clicks on the ENGLISH
> button,
> > he will be moved back to the:
> >
> > http://www.mydomain.com/apage.html
> >
> > Since we have more than 60 pages, we don't want to create 120 links on
> each
> > page. We would prefer to have two scripts, one that will insert a /fr
> after
> > the domain name (to move to the French site), and another one that will
> > remove this /fr in order to move to the English version of this page.
> >
> > Is this something that can be done with JavaScript?
> >
> > Normand P.
>
> ____________________________

Apologies - my previously posted script had a flaw; it toggled languages
regardless of the current page's language. Not good.

Here's a better solution:

_________ in a file http://www.mydomain.com/scripts/language.js :

var loc = document.location.toString();

var english = !(loc.search("/fr/")+1);

function fr(){
if(english){document.location = loc.replace(".com/",".com/fr/")}
}

function eng(){
if(!english){document.location = loc.replace("/fr/","/")}
}

_______________________ test pages:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<TITLE>apage</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">

<style>
.lang {
  text-decoration: underline;
  color:#0000ff;
}
</style>

<script src="scripts/language.js" type="text/javascript"></script>

</head>

<body style="background: #ffffff; margin: 40px; padding: 0px;">

<span class="lang" onClick="eng()">english</span>&nbsp;&nbsp;
<span class="lang" onClick="fr()">french</span>
<br><br>
<br><br>

<!--for testing only-->
<script type="text/javascript">
document.write("This page's address is:<br>" + document.location +
"<br><br>English content? " + english)
</script>
</body>
</html>

________________________________________

-alu
Received on Tue Oct 18 02:50:35 2005