Forum Moderators: open
I am doing a multilanguage site which has an index page (Call it A) where visitors can choose their preferred language - on clicking one of four flags they are taken to the appropriate welcome page (B, C, D or E). I would like to set a cookie so that when they return to A they are automatically redirected to B, C, D or E - whichever was their preferred language.
This means that I need to read and act on the cookie on A, and set the cookie automatically when they load B, C, D or E. (I did think about setting the cookie when they click the flag which sends them to B, C, D or E, but those flags are part of a flash animation, and I don't even know if I can set a cookie using FlashAction scipt. It seems to be easier to set it onload of the new page.)
Trouble is I don't know how to do any of this.
Can anyone help?
Paste those lines into your pages B, C, D etc.
<script language="JavaScript" type="text/javascript">
var d = new Date()
var dMonth = d.getTime() + 30*24*60*60*1000
d.setTime(dMonth)
document.cookie = 'startPage=' + location.href + '; expires=' + d.toGMTString()
function deleteCookie(){
var d = new Date(2000,1,1)
document.cookie = 'startPage=' + location.href + '; expires=' + d.toGMTString()
}
</script>
And in your page A paste those
<script language="JavaScript" type="text/javascript">
var c = document.cookie.split(';')
if(c.length >0){
for(m=0;m<c.length;m++){
if(c[m].indexOf('startPage')>-1){
location.replace(c[m].split('=')[1])
}
}
}
</script>
But so the user will not longer can load the page A (the cookie will always redirect to other page)
To void this, you can call to javascript function since your flag into your flash movie.
Now, your flag has an action like getURL('the url')
I suggest to add this line to your flag action
getURL('javascript:void deleteCookie()')
getURL('the url')
this line will call the javascript function wich delete the cookie at the moment to click de flag wich loads the page with the default language
greetings
(I am still not when the cookie is being set)
Should I email you the URL so you can see what I am doing wrong?
Thanks in advance for any help you give.
flaufs, I've seen your page and the problem seems to be that there's a sentence wich should be in one line and it's in two
This line
var d = new Date()
var dMonth = d.getTime() + 30*24*60*60*1000
d.setTime(dMonth)
document.cookie = 'startPage=' + location.href + '; expires=' + d.toGMTString()
function deleteCookie(){
var d = new Date(2000,1,1)
document.cookie = 'startPage=' + location.href + '; expires=' + d.toGMTString()
}
Anyway, I see that it is not necessary to use de deleteCookie function, so you can delete it, if you want, and it is not necessary neither the action I mentioned to the flag button into your flash.
So the things should see like this:
In your default page
<script language="JavaScript" type="text/javascript">
var c = document.cookie.split(';')
if(c.length >0){
for(m=0;m<c.length;m++){
if(c[m].indexOf('startPage')>-1){
location.replace(c[m].split('=')[1])
}
}
}
</script>
And in the wellcome pages in every language
<script language="JavaScript" type="text/javascript">
var d = new Date()
var dMonth = d.getTime() + 30*24*60*60*1000
d.setTime(dMonth)
document.cookie = 'startPage=' + location.href + '; expires=' + d.toGMTString()
</script>
Try now and tell me ;-)
Still having problems. (sorry for being so thick) The cookie appears to be set when I leave the language page chosen. (However, I'm not sure its being set correctly, as it doesn't show as "cookie:webpage", it simply shows as "languagechosen/" - perhaps this does not matter?)
Anyway, when I go back to the default page I don't get redirected despite the fact that I am storing a cookie. Also, if I choose a different language this time the cookie is not reset.
I really appreciate your time on this and once again, thanks to everyone who has commented.