Reputation: 59
I have a modal popup made in javascript where you can choose the language of a website, English or French. When you click English it'll load an English HTML page, and French it'll just remove the modal popup. How can I create a cookie to remember the choice of the user, so the modal is hidden until the cookie expires? I've come across the jQuery-cookie, but I don't know how to combine it with that onclick function I've created in Javascript. Any tips?
Javascript
function langMessage() {
this.messageBox = null;
this.popOut = function(messageText, en_lang, fr_lang) {
var english = document.createElement("div");
english.className = "english";
english.innerHTML = en_lang;
this.messageBox.appendChild(english);
english.onclick = function() {
window.location.href = "test-en.html";
}
var french = document.createElement("div");
french.className = "french";
french.innerHTML = fr_lang;
this.messageBox.appendChild(french);
french.onclick = function() {
this.parentNode.Code.remove();
}
}
HTML
<div class="modal">
<script type="text/javascript">
var message = new langMessage();
message.popOut("Please choose your preferred language", "English", "French");
</script>
</div>
Upvotes: 1
Views: 561
Reputation: 5093
Before you get too enthusiastic about this, read up on the "accept-language" attribute of an HTTP request. Essentially you can pick up which language the user prefers from the request, as a starting point anyway.
It's not an absolute guide to which language should be used, but it's a good starting point.
Upvotes: 1