-1

I manage a website where I would like to set a cookie for chosen language.

The only parameter I have to work with is that the user is clicking on a language dropdown with classes for each language - when they click their preferred language it is set in the meta:

lang="sv" xml:lang="sv"

I use the jQuery cookie plugin on the site. Is it possible to save the language choice in a cookie here?

Jerry Svensson
  • 267
  • 2
  • 12
  • Why would it *not* be possible to save a cookie? Have you tried something and are you having problems with the code? – JJJ Apr 11 '16 at 06:52
  • Why you are not using session? – itzmukeshy7 Apr 11 '16 at 07:12
  • i just started to venture in the cookieland - and Im unsure how to do it frankly. – Jerry Svensson Apr 11 '16 at 07:18
  • @juhana could you point me in a direction for saving a session that works in my case? – Jerry Svensson Apr 11 '16 at 07:20
  • Have you read the plugin's documentation? – JJJ Apr 11 '16 at 07:38
  • @Juhana yes of course - I don´t fully understand how to do this anyhow. – Jerry Svensson Apr 11 '16 at 07:50
  • Sorry, it's impossible to help if you don't give any more details. The documentation tells how to set and read cookies, and so does Velimir's answer below. You'll have to be more specific which part exactly you don't know how to do. – JJJ Apr 11 '16 at 07:51
  • I basically want to set a session cookie that saves the users language choice. I don´t now how to do this - nor from reading he documentation nor how to implement it from the answer below. – Jerry Svensson Apr 11 '16 at 08:17
  • @Jorrex LocalStorage sounds interesting. Will try to google a solution for my needs - If you would like to point me in a direction that would be helpful. Thanks! – Jerry Svensson Apr 11 '16 at 08:34

2 Answers2

0

to set an item with localStorage: localStorage.setItem("language", "english")
to get the value with localStorage: localStorage.getItem("language")
to remove an item with localStorage: localStorage.removeItem("language")

as simple as that :)

W3Schools explanation: here

Jorrex
  • 1,404
  • 2
  • 13
  • 28
-1

To set a cookie use this: $.cookie("lang", 1); To read the cookie later use: lang = $.cookie("lang");

Possible dublicate of:How do I set/unset cookie with jQuery?

Community
  • 1
  • 1
Velimir Tchatchevsky
  • 2,487
  • 1
  • 13
  • 18