Thanks all for you answers.
Here is an improved version where I keep the other URL parameters
(gwt.codeserver, ...)
var currLocation = $wnd.location.toString();
var noHistoryCurrLocArray = currLocation.split("#");
var noHistoryCurrLoc = noHistoryCurrLocArray[0];
var historyToken = noHistoryCurrLocArray[1];
// Replace locale=.. if found
if (noHistoryCurrLoc.match(/(\?|&)locale=(\w*)/g)) {
noHistoryCurrLoc =
noHistoryCurrLoc.replace(/(\?|&)locale=(\w*)/g, "$1locale=" + newLocale);
}
// Else, add it to the end of the query
else {
var separator = noHistoryCurrLoc.indexOf('?') == -1 ? '?' : '&';
noHistoryCurrLoc = noHistoryCurrLoc + separator + "locale=" +
newLocale;
}
$wnd.location.href = noHistoryCurrLoc + '#'+historyToken; //$wnd
Le mardi 16 juin 2009 16:08:21 UTC+2, Raymond Domingo a écrit :
>
> Hi Bhavik,
>
> FYI
> I have used your script sparely, but successfully for some time now,
> thank you for sharing.
>
> I recently discovered it broke my recenlty added history support. That
> is when I extended your script to support history tokens. Now it also
> supports history tokens.
>
> var currLocation = $wnd.location.toString();
> var noHistoryCurrLocArray =
> currLocation.split("#");
> var noHistoryCurrLoc =
> noHistoryCurrLocArray[0];
> var historyToken = noHistoryCurrLocArray
> [1];
> var locArray=noHistoryCurrLoc.split("?");
> var newHref = locArray[0]+"?
> locale="+newLocale;
>
> // alert('currLocation'+currLocation);
> // alert
> ('noHistoryCurrLocArray'+noHistoryCurrLocArray);
> // alert
> ('noHistoryCurrLoc'+noHistoryCurrLoc);
> // alert('historyToken'+historyToken);
> // alert('locArray'+locArray);
> // alert('newHref'+newHref);
>
> $wnd.location.href=newHref
> +'#'+historyToken;
>
>
> On 14 mei, 14:13, Bhavik <[email protected]> wrote:
> > Hello Friends,
> >
> > I too recently had the same problem as yours. My requirement was a
> > user can change the language on his wish from the ComboBox.
> >
> > So the solution I did with is I used JSNI (JavaScript Native
> > Interface). - Javascript to be written into Java file.
> >
> > I put a combox. and on its "onSelect()" method in Listener Method of
> > ComboBox, I get the value like "en_US" or "fr_FR" like this....
> >
> > Then I created an innerclass and created a JSNI method named
> > changeLocale like :
> >
> > class Locale
> > {
> > private native void changeLocale(String newLocale)/*-{
> >
> > //alert("Language changed to : "+newLocale);
> >
> > var currLocation = $wnd.location.toString();
> > //alert("currLocation : "+currLocation);
> >
> > var noHistoryCurrLocArray = currLocation.split("#");
> > //alert("noHistoryCurrLocArray:
> "+noHistoryCurrLocArray);
> >
> > var noHistoryCurrLoc = noHistoryCurrLocArray[0];
> > //alert("noHistoryCurrLoc : "+noHistoryCurrLoc);
> >
> > var locArray = noHistoryCurrLoc.split("?");
> > //alert("locArray : "+locArray);
> > $wnd.location.href = locArray[0]+"?locale="+newLocale;
> //$wnd
> > }-*/;
> > }
> >
> > Now in onSelect() method of Combobox create an instance of Locale and
> > then call the changeLocale() native method.
> >
> > Good Luck. This will work as I did the same......
--
You received this message because you are subscribed to the Google Groups "GWT
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.