-1

I made a simple website that includes two language versions, one Turkish and one English, my index page is a page that offers Turkish | English link directing into index-tr and index-en. My question is how to make the index page remember what did the certain IPs selected when they first accessed the site. I mean, if I selected Turkish for the first time when I access the site another time it should remember that I've selected Turkish and should not direct me to the index page but instead, it should open index-tr.

I've used HTML and CSS only, no Javascript included.

I hope I made it clear.

Thanks in advance.

Fornicras
  • 3
  • 2

3 Answers3

1

I don't think this is possible with HTML CSS only, you have to use JavaScript,

Use localStorage

if (typeof(Storage) !== "undefined"){
  localStorage.setItem('lang', 'tur');
} else localStorage.getItem('lang')

MDN

Abhishek Pandey
  • 13,302
  • 8
  • 38
  • 68
1

You can't store properties in HTML or CSS to be remembered for a period of time.

You have to use JavaScript or something server side, like PHP.

With JavaScript you could use localStorage.

The localStorage property allows you to access a local Storage object. localStorage is similar to sessionStorage. The only difference is that, while data stored in localStorage has no expiration time, data stored in sessionStorage gets cleared when the browsing session ends—that is, when the browser is closed.

You can write something like this

localStorage.setItem('language', 'tr') // Turkish language

You can overwrite this value by just overwriting the language with setItem()

localStorage.setItem('language', 'en') // English language

Now you can do something with it.

if(localStorage.getItem('language') == 'tr') {
    // Language it Turkish, redirect or what ever JS code here.
} else {
    // Language is not Turkish, but something other then 'tr'    
}

More documentation and example's you can find here

Red
  • 6,599
  • 9
  • 43
  • 85
  • What if user is visiting site for very first time and `localStorage` is `null`? – Abhishek Pandey Jun 14 '17 at 08:49
  • Well, thats on the developer. He can show a popup with 2 options, `which site do you want to visit? ..` then give `turkish` and `english` or just set a default value. – Red Jun 14 '17 at 08:51
0

You can't do it with html and css, you have to do it with or at the server (cookies in php)

eslam masoud
  • 413
  • 1
  • 3
  • 10