Redirection with Cookies

Discussion in 'Javascript' started by Karl Gralowetz, Jul 20, 2004.

  1. Hello, Scriptmasters!

    I have a big Problem with some Javascript:
    One a website, i want to paste some "confirm" there, if the
    visitor's browserlanguage is not "de".
    when he confirm, he'll be redirected to the 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 expDays = 100;
    var exp = new Date();
    exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

    function getCookieVal (offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
    }
    function GetCookie (reisefotos) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen)
    {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
    return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
    }
    return null;
    }
    function SetCookie (name, value) {
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
    }
    function DeleteCookie (name) {
    var exp = new Date();
    exp.setTime (exp.getTime() - 1);
    var cval = GetCookie (name);
    document.cookie = name + "=" + cval + "; expires=" +
    exp.toGMTString();
    }
    var favorite = GetCookie('reisefotos');
    if (navigator.appName == 'Netscape')
    var language = navigator.language
    else
    var language = navigator.browserLanguage
    if (favorite != null && language.indexOf('it') > -1) {
    SetCookie('reisefotos', this.name, exp);
    }
    if (favorite != null && language.indexOf('fr') > -1) {
    var abfrage = confirm ("Ton " + navigator.appName + " langue est le "
    + language + ".\n\Voudrais-tu changer à la version
    française?\n\-Traduction Babelfish-")
    if (abfrage)
    SetCookie('reisefotos', this.name, exp)
    window.location="http://www.yahoo.fr"
    }
    else {
    var abfrage = confirm ("Your " + navigator.appName + " Language is " +
    language + ".\n\Would you like to switch to the English
    Version?\n\-Translated by Babelfish-")
    if (abfrage)
    SetCookie('reisefotos', this.name, exp)
    window.location="http://www.yahoo.com"
    }
    }
    // End -->
    </script>
    Karl Gralowetz, Jul 20, 2004
    #1
    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,777
    =?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,479
    Hans Kesting
    Feb 3, 2005
  3. Andy Fish
    Replies:
    3
    Views:
    6,520
    Fredrik Lindner
    Nov 6, 2003
  4. _Who
    Replies:
    7
    Views:
    2,653
  5. Karl

    Redirection with Cookies

    Karl, Jul 21, 2004, in forum: Javascript
    Replies:
    1
    Views:
    100
    Dr John Stockton
    Jul 21, 2004
Loading...

Share This Page