Note that there are some explanatory texts on larger screens.

plurals
  1. POIncrement browser cookie in Javascript? (setCookie, getCookie method)
    primarykey
    data
    text
    <p>Logically this seems to be correct. However, either the setCookie or getCookie functions simply aren't firing?</p> <p>cookie.js</p> <pre><code>function setCookie(c_name,value,exdays) { var exdate=new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); document.cookie=c_name + "=" + c_value; } function getCookie(c_name) { var c_value = document.cookie; var c_start = c_value.indexOf(" " + c_name + "="); if (c_start == -1) { c_start = c_value.indexOf(c_name + "="); } if (c_start == -1) { c_value = null; } else { c_start = c_value.indexOf("=", c_start) + 1; var c_end = c_value.indexOf(";", c_start); if (c_end == -1) { c_end = c_value.length; } c_value = unescape(c_value.substring(c_start,c_end)); } return c_value; } </code></pre> <p>index.php</p> <pre><code>var newCookie = parseInt(getCookie("liked_count")); if(newCookie != null &amp;&amp; newCookie != ""){ newCookie += 1; setCookie("liked_count",newCookie,5); }else{ setCookie("liked_count",1,5); } </code></pre> <p>No matter which side of the if statement it follows, no cookie is set regardless. From what I can tell there are no errors or warnings, so could it be that it cannot find the setCookie and getCookie function inside the my cookies.js file?</p> <p>The cookies.js file successfully locates, so I'm at my wits end here.</p> <pre><code>&lt;head&gt; &lt;script type="text/javascript" src="assets/js/cookies.js"&gt;&lt;/script&gt; &lt;/head&gt; </code></pre> <p>Any help would be much appreciated!</p> <p>EDIT:</p> <p>Oh sorry, this is embarrassing... It turns out that the cookie.js file was being cached and I had actually moved file location. It was that simple. Sorry for this waste of time!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload