diff options
| author | sD <stoned@derpymail.org> | 2020-06-01 12:49:56 +0200 |
|---|---|---|
| committer | sD <stoned@derpymail.org> | 2020-06-01 12:49:56 +0200 |
| commit | f98e25772c45ef8d16708b38e7a8d0c88cbd2086 (patch) | |
| tree | 2a818a72478ad72e56ad2b40ceb5fd0929a114f6 /webAO/client.js | |
| parent | 3b591a5d7309b07ff8f47d936e3b145c7c4d8017 (diff) | |
don't cause an exception if the cookie doesn't exist
Diffstat (limited to 'webAO/client.js')
| -rw-r--r-- | webAO/client.js | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/webAO/client.js b/webAO/client.js index 52b7976..93d374f 100644 --- a/webAO/client.js +++ b/webAO/client.js @@ -1971,19 +1971,23 @@ class INI { * @param {String} cname The name of the cookie to return */ function getCookie(cname) { - var name = cname + "="; - var decodedCookie = decodeURIComponent(document.cookie); - var ca = decodedCookie.split(';'); - for (var i = 0; i < ca.length; i++) { - var c = ca[i]; - while (c.charAt(0) === ' ') { - c = c.substring(1); - } - if (c.indexOf(name) === 0) { - return c.substring(name.length, c.length); + try { + const name = cname + "="; + const decodedCookie = decodeURIComponent(document.cookie); + const ca = decodedCookie.split(';'); + for (var i = 0; i < ca.length; i++) { + var 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 ""; } - return ""; } /** |
