Results 1 to 2 of 2

Thread: Javascript not working on Firefox and Google Chome

  1. #1
    Join Date
    Feb 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Javascript not working on Firefox and Google Chome

    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
    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?

  2. #2
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,876
    Thanks
    49
    Thanked 264 Times in 256 Posts
    Blog Entries
    56

    Default

    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:
    Code:
    <body>
    <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>
    </body>
    ===
    Arie Molendijk.
    Last edited by molendijk; 02-08-2010 at 03:15 PM. Reason: Correct error

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •