35 lines
916 B
JavaScript
35 lines
916 B
JavaScript
window.cookies = {
|
|
Read: function (name) {
|
|
try {
|
|
const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
|
|
if (match) return decodeURIComponent(match[2]);
|
|
return '';
|
|
} catch (e) {
|
|
return '';
|
|
}
|
|
},
|
|
Write: function (name, value, expiresIso) {
|
|
try {
|
|
var expires = '';
|
|
if (expiresIso) {
|
|
expires = '; expires=' + new Date(expiresIso).toUTCString();
|
|
}
|
|
document.cookie = name + '=' + encodeURIComponent(value) + expires + '; path=/';
|
|
} catch (e) { }
|
|
}
|
|
};
|
|
|
|
window.getBrowserLanguage = function () {
|
|
try {
|
|
return (navigator.languages && navigator.languages[0]) || navigator.language || navigator.userLanguage || '';
|
|
} catch (e) {
|
|
return '';
|
|
}
|
|
};
|
|
|
|
window.setHtmlLang = function (lang) {
|
|
try {
|
|
if (document && document.documentElement) document.documentElement.lang = lang || '';
|
|
} catch (e) { }
|
|
};
|