Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Redirection with Cookies

Reply
Thread Tools

Redirection with Cookies

 
 
Karl
Guest
Posts: n/a
 
      07-21-2004
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[i] = cookies[i].split(/=/);
cookies[i][1] = unescape(cookies[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.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%2Fst efan.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>
 
Reply With Quote
 
 
 
 
Dr John Stockton
Guest
Posts: n/a
 
      07-21-2004
JRS: In article <(E-Mail Removed) >,
dated Wed, 21 Jul 2004 00:51:10, seen in news:comp.lang.javascript, Karl
<(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Give Request.Cookies and Response.Cookies is there any reason to use another method to use cookies? _Who ASP .Net 7 09-18-2008 07:49 PM
Response.Cookies vs Request.Cookies Alex Nitulescu ASP .Net 1 02-03-2005 09:43 AM
Cookies & Redirection Jason Williard ASP .Net 1 10-13-2004 08:35 AM
Redirection with Cookies Karl Gralowetz Javascript 0 07-20-2004 05:42 PM
Persistent Cookies vs. session cookies Andy Fish Java 3 11-06-2003 10:44 AM



Advertisments