Redirection with Cookies

Discussion in 'Javascript' started by Karl, Jul 21, 2004.

  1. Karl

    Karl Guest

    Hi there!

    I have a big Problem with some Javascript:
    On a website, i want to paste some "confirm", if the
    visitor's browserlanguage is not "de".
    when he confirm, he'll be redirected to the english-translation of
    this page.

    to store this information, because it's ugly to ask on every single
    visit, if he want to switch to the translation.
    but i can't find out, why the script isn't working.

    i please you to look at the source and answer me, if you have some
    solution(s).
    thanks, karl!

    <SCRIPT LANGUAGE="JavaScript">
    <!--
    var Count = 0;
    if (navigator.appName == 'Netscape')
    { var Language = navigator.language }
    else {
    var Language = navigator.browserLanguage
    }
    var cookies = document.cookie.split(/; /);
    for(var i = 0; i < cookies.length; i++)
    {
    cookies = cookies.split(/=/);
    cookies[1] = unescape(cookies[1]);
    if(cookies[0] == 'Count') Count = cookies[1];
    if(cookies[0] == 'Language') Language = cookies[1];
    if(cookies[0] == 'Benutzer') Benutzer = cookies[1];
    }

    //Here comes the Problem:
    //if 1st time here (count = 0) AND language = de
    //I tried a few methods but the script isn't working

    if (Count = 0 && Language.indexOf('de') > -1)
    {
    var Benutzer=confirm ("Your " + navigator.appName + " Language
    is " + Language + ".\n\Would you like to switch to the English
    Version?\n\-Translated by Babelfish-")
    if (Benutzer==true)
    {
    Benutzer = window.location="http://world.altavista.com/babelfish/trurl_load?url=http%3A%2F%2Fmembers.chello.at%2Fstefan.szeiler&lp=de_en";
    }
    else { Benutzer = window.location="#"; }
    }

    Count++;

    //Expire of Cookies in 1 year

    var Datum = new Date();
    Datum.setFullYear(Datum.getFullYear() + 1);
    var expires = "expires=" + Datum.toGMTString();

    //Cookies write:

    document.cookie = "Count=" + escape(Count) + "; " + expires;
    document.cookie = "Language=" + escape(Language) + "; " + expires;
    document.cookie = "Benutzer=" + escape(Benutzer) + "; " + expires;
    // Ende -->
    </script>
     
    Karl, Jul 21, 2004
    #1
    1. Advertising

  2. JRS: In article <>,
    dated Wed, 21 Jul 2004 00:51:10, seen in news:comp.lang.javascript, Karl
    <> posted :
    >
    >var Datum = new Date();
    >Datum.setFullYear(Datum.getFullYear() + 1);
    >var expires = "expires=" + Datum.toGMTString();


    FullYear is not always available; why not use the shorter

    Datum.setMonth(Datum.getMonth() + 12);


    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
    <URL:http://jibbering.com/faq/> JL / RC : FAQ for 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.
     
    Dr John Stockton, Jul 21, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason Williard

    Cookies & Redirection

    Jason Williard, Oct 13, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,799
    =?Utf-8?B?UHN5Y2hv?=
    Oct 13, 2004
  2. Alex Nitulescu

    Response.Cookies vs Request.Cookies

    Alex Nitulescu, Feb 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,631
    Hans Kesting
    Feb 3, 2005
  3. Andy Fish
    Replies:
    3
    Views:
    6,612
    Fredrik Lindner
    Nov 6, 2003
  4. _Who
    Replies:
    7
    Views:
    2,776
  5. Karl Gralowetz

    Redirection with Cookies

    Karl Gralowetz, Jul 20, 2004, in forum: Javascript
    Replies:
    0
    Views:
    109
    Karl Gralowetz
    Jul 20, 2004
Loading...

Share This Page