The mcrSf.cookieDel() method requires a minimum of one argument and has an undefined return value.
The required argument defines the cookie name. The optional argument defines the path that the cookie belongs to. The cookie path should be defined to ensure that the right cookie will be deleted. Some browsers will not allow deleting a cookie without specifying the correct path.
Please Note: Due to security issues and other problems, Google Chrome and other popular browsers have disabled storing cookies for local files. Cookies can only be stored and retrieved for files that are served from a webserver.
Parameters
Parameter | Type | Description |
---|---|---|
cookieName | String | The name of the cookie. |
cookiePath (Optional) | String | The path of the cookie. Optional, default value of '/' . |
Return Value
Type | Description |
---|---|
undefined | The method has no return value. |
The Stand-Alone Function
Below code is ready for copy/paste and will work just fine on it's own, without linking the mcrSf
library file.
function cookieDel(cookieName, cookiePath) {
var cookieString = cookieName + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
if (cookiePath !== "") {
cookiePath = cookiePath || "/";
cookieString += "; path=" + cookiePath;
}
document.cookie = cookieString;
}
The mcrSf
Library Method
/**
* Delete (remove) a cookie
* @version 0.1
* @param {String} cookieName - the name of the cookie
* @param {String} [cookiePath="/"] - the path of the cookie (default: "path=/")
* @return {undefined} - method has no return value
*
* STRATEGY: Set expiry date to 01-01-1970 to the cookie
*/
cookieDel: function(cookieName, cookiePath) {
var cookieString = cookieName + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
if (cookiePath !== "") {
cookiePath = cookiePath || "/";
cookieString += "; path=" + cookiePath;
}
document.cookie = cookieString;
}
Version History
Revision Date | Details |
---|---|
0.1 05-Aug-17 | First release, cookieDel() . |