diff options
| author | stonedDiscord <Tukz@gmx.de> | 2022-03-09 19:16:36 +0100 |
|---|---|---|
| committer | stonedDiscord <Tukz@gmx.de> | 2022-03-09 19:16:36 +0100 |
| commit | e375a416503b07aa89151e17241ca3606aec0b2b (patch) | |
| tree | 046a274702cbdca71379959d1e245f2310d3b92e /webAO/utils/getCookie.js | |
| parent | 38a05ca3bb8ab972327c938a7a58d4aa07572daf (diff) | |
| parent | 679bc9be8b0459d298ac1ac3f3b7e61278c184d9 (diff) | |
Merge branch 'master' of https://github.com/AttorneyOnline/webAO
Diffstat (limited to 'webAO/utils/getCookie.js')
| -rw-r--r-- | webAO/utils/getCookie.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/webAO/utils/getCookie.js b/webAO/utils/getCookie.js new file mode 100644 index 0000000..3be0733 --- /dev/null +++ b/webAO/utils/getCookie.js @@ -0,0 +1,26 @@ +/** + * read a cookie from storage + * got this from w3schools + * https://www.w3schools.com/js/js_cookies.asp + * @param {String} cname The name of the cookie to return + */ +const getCookie = (cname) => { + try { + const name = `${cname}=`; + const decodedCookie = decodeURIComponent(document.cookie); + const ca = decodedCookie.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 ''; + } catch (error) { + return ''; + } +}; +export default getCookie; |
