From f98e25772c45ef8d16708b38e7a8d0c88cbd2086 Mon Sep 17 00:00:00 2001 From: sD Date: Mon, 1 Jun 2020 12:49:56 +0200 Subject: don't cause an exception if the cookie doesn't exist --- webAO/client.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'webAO/client.js') 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 ""; } /** -- cgit