![]() Topic awaiting preservation: setting cookies (Page 1 of 1) |
|
---|---|
Paranoid (IV) Inmate From: Greenville, SC, USA |
![]() Hello, |
Maniac (V) Mad Scientist From: 100101010011 <-- right about here |
![]() Cookies in Javascript |
Paranoid (IV) Inmate From: beyond the gray sky |
![]() http://www.netspade.com/articles/javascript/cookies.xml |
Paranoid (IV) Inmate From: Greenville, SC, USA |
![]() well so far I have this: code: function setCookie() {
code: <button type="button" onclick="setCookie()">foo</button>
code: var pairs = document.cookie.split(';');
code: location.href="http://www.url.com/englishindex.html"
|
Neurotic (0) Inmate Newly admitted From: |
![]() Hey jive, code: // Author: Travis Beckham | squidfingers.com var Cookie = { set : function(name,value,days) { if(days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else { var expires = ""; } document.cookie = name+"="+value+expires+"; path=/"; } , get : function(name) { name += "="; var s = document.cookie.split("; "); for(var i = 0; i < s.length; i++) { var c = s[i]; if(c.indexOf(name) == 0) { return unescape(c.substring(name.length,c.length)); } } return null; }, erase : function(name) { this.set(name,"",-1); }, enabled : function() { this.set("cookietest","cookietest"); return this.get("cookietest") != null; } };
code: function ChangeLanguage(language, doReload) { if(language) { Cookie.set('pref_language',language,365); } if(doReload) window.localtion.reload(); } function Redirect(language) { switch (language) { case 'spanish': window.location = 'index_spanish.html'; break; case 'english': window.location = 'index_english.html'; break; default: window.location = 'index_nopref.html'; break; } } function RedirectUser() { var where = Cookie.get('pref_language'); where = where ? where.toString() : 0; alert(where); Redirect(where); }
code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><title>Index Page</title> <script language="javascript" type="text/javascript" src="cookies.js"></script> <script language="javascript" type="text/javascript" src="language.js"></script> </head> <body onload="RedirectUser();"> <p><a href="index.html">Smart Index</a> | <a href="index_english.html">English</a> | <a href="index_spanish.html">Español</a> | <a href="index_nopref.html">No Preference Set</a></p> <h1>Index Page</h1> <p>This page should redirect you to your preferred language.</p> </body> </html>
code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><title>English Page</title></head> <script language="javascript" type="text/javascript" src="cookies.js"></script> <script language="javascript" type="text/javascript" src="language.js"></script> <body> <p><a href="index.html">Smart Index</a> | <a href="index_english.html">English</a> | <a href="index_spanish.html">Español</a> | <a href="index_nopref.html">No Preference Set</a></p> <h1>English</h1> <p>Hello! This is an English page.</p> <p>Your current language is: <script language="javascript" type="text/javascript"> //<![CDATA[ // Remove this line if you do not want the menu to ever be collapsable var prefLanguageValue = Cookie.get('pref_language') if(prefLanguageValue) document.write(prefLanguageValue) else document.write('null'); //]]> </script> </p> <hr/> <dl> <dt>Language/Idioma</dt> <dd><a href="#" onclick="ChangeLanguage('english');window.location.reload();">English</a></dd> <dd><a href="#" onclick="ChangeLanguage('spanish');window.location.reload();">Español</a></dd> </dl> <dl> <dt>Test Tools</dt> <dd><input type="button" value="RedirectUser()" onclick="javascript:RedirectUser();" name="refresh" /></dd> <dd><input type="button" value="Erase Preference Cookie" onclick="javascript:Cookie.erase('pref_language');" name="refresh" /></dd> </dl> </body> </html>
code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><title>Spanish Page</title> <script language="javascript" type="text/javascript" src="cookies.js"></script> <script language="javascript" type="text/javascript" src="language.js"></script> </head> <body> <p><a href="index.html">Smart Index</a> | <a href="index_english.html">English</a> | <a href="index_spanish.html">Español</a> | <a href="index_nopref.html">No Preference Set</a></p> <h1>Español</h1> <p>¡Hola! Esto es una página española.</p> <p>Your current language is: <script language="javascript" type="text/javascript"> //<![CDATA[ // Remove this line if you do not want the menu to ever be collapsable var prefLanguageValue = Cookie.get('pref_language') if(prefLanguageValue) document.write(prefLanguageValue) else document.write('null'); //]]> </script> </p> <hr/> <dl> <dt>Language/Idioma</dt> <dd><a href="#" onclick="ChangeLanguage('english');window.location.reload();">English</a></dd> <dd><a href="#" onclick="ChangeLanguage('spanish');window.location.reload();">Español</a></dd> </dl> <dl> <dt>Test Tools</dt> <dd><input type="button" value="RedirectUser()" onclick="javascript:RedirectUser();" name="refresh" /></dd> <dd><input type="button" value="Erase Preference Cookie" onclick="javascript:Cookie.erase('pref_language');window.location.reload();" name="refresh" /></dd> </dl> </body> </html>
code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><title>No Preference</title></head> <script language="javascript" type="text/javascript" src="cookies.js"></script> <script language="javascript" type="text/javascript" src="language.js"></script> <body> <p><a href="index.html">Smart Index</a> | <a href="index_english.html">English</a> | <a href="index_spanish.html">Español</a> | <a href="index_nopref.html">No Preference Set</a></p> <h1>No Preference page</h1> <p> <script language="javascript" type="text/javascript"> //<![CDATA[ // Remove this line if you do not want the menu to ever be collapsable var prefLanguageValue = Cookie.get('pref_language') if(prefLanguageValue) { document.write('Your current language is:<b>' + prefLanguageValue + '</b>'); } else document.write('You have not currently selected a language'); //]]> </script> </p> <p>This site is made for english or spanish. Choose your language</p> <p>Este sitio se causa inglés o español. Escoja su idioma.</p> <dl> <dt>Language/Idioma</dt> <dd><a href="#" onclick="ChangeLanguage('english');window.location.reload();">English</a></dd> <dd><a href="#" onclick="ChangeLanguage('spanish');window.location.reload();">Español</a></dd> </dl> <dl> <dt>Test Tools</dt> <dd><input type="button" value="RedirectUser()" onclick="javascript:RedirectUser();" name="refresh" /></dd> <dd><input type="button" value="Erase Preference Cookie" onclick="javascript:Cookie.erase('pref_language');" name="refresh" /></dd> </dl> </body> </html>
|
Obsessive-Compulsive (I) Inmate From: |
![]() i'm also looking at the same issue for a bilingual website. Is this above solution vunlerable to being penalised by search engines for using the body onload event and if so what is the workaround with javascript/cookies? |
Maniac (V) Mad Scientist From: 100101010011 <-- right about here |
![]() As long as you have links to the other language sections of your site on your main page you should not be penalized by the search engines, ie they should find both. I'm not an SEO whiz however. |
Obsessive-Compulsive (I) Inmate From: |
![]() thanks, only time will tell. |