How to Set a Cookie When Changing the Language of the Website

How to Set a Cookie When Changing the Language of the Website thumbnail
Set website cookies in Javascript.

Javascript provides you with a quick way to set a cookie when a user chooses a language on your site. This means you can detect the selected user language the next time the visitor navigates to your web pages. Setting language settings is called localization, and it improves global usability for your website readers. Javascript supports any language website including PHP, HTML, VB.NET or C#. This makes it easy for any developer to implement language cookies.

Instructions

    • 1

      Create the expiration date for the coffee. When the expiration date is reached, the browser deletes the cookie. The next time the user accesses the site, a new cookie is set. The following code creates a cookie that lasts 90 days on the user's browser:

      var expire_date =new Date();
      expire_date.setDate(expire_date.getDate()+90);

    • 2

      Create the cookie name. You can name the cookie any recognizable name. The following code creates a Javascript variable for the cookie name:

      var cookie_name = "Language";

    • 3

      Create the cookie and set the language. You can use the standard characters for each language (see Resources), but you can use any customized standard for your cookie. The following code sets a language cookie for your user:

      document.cookie=cookie_name + "=" + "en"

      The code above sets the cookie to "English" using the two-character abbreviation "en."

Related Searches:

References

Resources

  • Photo Credit cookie image by Vera Kailova from Fotolia.com

Comments

You May Also Like

  • How to Use HTML Cookies

    A webmaster who wants to track clients or retrieve information uses cookies. CGI and Javascript are used to set cookies using HTML...

  • JavaScript & Cookies Tutorial

    Javascript provides programmers with the language to create, retrieve and read cookies on the user's browser. Cookies are tiny files placed on...

  • How to Set Facebook Language to Pirate

    Now a days, almost everyone has a Facebook. You can do practically anything on it from staying in touch to playing games...

  • How to Create a Cookie File

    Cookies are tiny files left on a website reader's computer that saves a value for the next web page visit. Cookies have...

  • How to Unblock Cookies on Your Computer

    Unblocking cookies on your computer is necessary for some websites--particularly those with shopping carts or log-in portals. Cookies are tracking devices that...

  • How to Use HTML Cookies

    HTML cookies are small files that Web sites use to store information about users and their interaction with that particular Web site,...

  • The Best Browser Settings

    The best browser settings are those that protect your computer from attacks, but still allow for Web functionality. Browser settings control your...

  • How to Set Cookie Preferences on Your Browser

    Cookies are text documents that Web sites save onto your hard disk so that the sites will "remember" you on your next...

  • How to Delete Cookies Using JavaScript

    Cookies are small data files stored by your Web browser when you visit a website. Each cookie is unique to the user,...

Related Ads

Featured