Allowing only certain paths
You can check the value of window.location.path
for this. Remember that rarely some paths have aliases. Check the following code that only works in the main page as an example:
if (window.location.pathname === "/" || window.location.pathname === "/Default.aspx")
{
// your code here
}
Translations
You should use Artado's Lang
cookie for the language. See the following code:
function getCookie(cname) {
let name = cname + "=";
let ca = document.cookie.split(';');
for(let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
var lang = getCookie("Lang");
if (lang === "")
{
lang = "en";
}
const translations = {
tr: {
title: "Merhaba!"
},
en: {
title: "Hello!"
},
el: {
title: "Γεια σου!"
}
};
const t = translations[lang] || translations.en;
someElement.innerHTML = `<h1 class="title">${t.title}</h1>`;
Credit to w3schools for getCookie code.
If you have more tips, share them below!