Redirection with Cookies

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Karl

    #1

    Redirection with Cookies

    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="JavaS cript">
    <!--
    var Count = 0;
    if (navigator.appN ame == 'Netscape')
    { var Language = navigator.langu age }
    else {
    var Language = navigator.brows erLanguage
    }
    var cookies = document.cookie .split(/; /);
    for(var i = 0; i < cookies.length; i++)
    {
    cookies[i] = cookies[i].split(/=/);
    cookies[i][1] = unescape(cookie s[i][1]);
    if(cookies[i][0] == 'Count') Count = cookies[i][1];
    if(cookies[i][0] == 'Language') Language = cookies[i][1];
    if(cookies[i][0] == 'Benutzer') Benutzer = cookies[i][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.indexO f('de') > -1)
    {
    var Benutzer=confir m ("Your " + navigator.appNa me + " 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%2Fme mbers.chello.at %2Fstefan.szeil er&lp=de_en";
    }
    else { Benutzer = window.location ="#"; }
    }

    Count++;

    //Expire of Cookies in 1 year

    var Datum = new Date();
    Datum.setFullYe ar(Datum.getFul lYear() + 1);
    var expires = "expires=" + Datum.toGMTStri ng();

    //Cookies write:

    document.cookie = "Count=" + escape(Count) + "; " + expires;
    document.cookie = "Language=" + escape(Language ) + "; " + expires;
    document.cookie = "Benutzer=" + escape(Benutzer ) + "; " + expires;
    // Ende -->
    </script>
  • Dr John Stockton

    #2
    Re: Redirection with Cookies

    JRS: In article <d89392e1.04072 02351.11dd4edc@ posting.google. com>,
    dated Wed, 21 Jul 2004 00:51:10, seen in news:comp.lang. javascript, Karl
    <antidotcom@web .de> posted :[color=blue]
    >
    >var Datum = new Date();
    >Datum.setFullY ear(Datum.getFu llYear() + 1);
    >var expires = "expires=" + Datum.toGMTStri ng();[/color]

    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.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

    Comment

    Working...