View Full Version : Javascript not working on Firefox and Google Chome

02-06-2010, 09:50 PM
I have a problem with my javascript which doesn't work properly on certain browsers, to be accurate Firefox and Google Chrome (tested with IE7, IE8, Opera[latest version], Firefox[latest version] and Google Chrome[latest version]).

The code

function changeLanguage(lang)
var url = window.location.href;
var filename = url.substring(url.lastIndexOf('/')+1);
var pathname = url.substring(0, url.lastIndexOf('/')+1);
if (lang == 'en' && url.indexOf("en/") == '-1')
window.navigate(pathname +"en/"+ filename);
if (lang == 'pl' && url.lastIndexOf("en/") != '-1')
var pathname = url.substring(0, url.lastIndexOf('/')-2);
window.navigate(pathname + filename);

What is it meant to be doing? It should navigate to a different url depends on the parameter passed to the function (and after passing some checks). More practically it changes the language on the website. I've used it with images of the flags using onClick event. It does work on Opera and IE but it doesn't work on Firefox and Google Chrome (nothing happens when I press a flag).

Any ideas?

02-08-2010, 03:13 PM
That's because window.navigate is not a function in (at least) Firefox, Chrome and Flock. You shouldn't use onclick="window.navigate('http://www.some_url.com')" but onclick="window.location='http://www.some_url.com'". Try this piece of code:
<button onclick="window.navigate('http://www.google.com')">Go to Google using window.navigate</button><br><br>
<button onclick="window.location='http://www.google.com'">Go to Google using window.location</button>
Arie Molendijk.