I am using an html page builder by unlayer. Once user clicks save button I get the html like this:
document.getElementById("save").addEventListener("click", () => {
unlayer.exportHtml(function (data) {
var bl = new Blob([html], { type: "text/plain" });
var a = document.createElement("a");
a.download = "download-name-here.html";
a.hidden = true;
document.body.appendChild(a);
let blob = a;
a.href = fetch(a).then(r => r.blob());
a.click();
const reader = new FileReader();
// This fires after the blob has been read/loaded.
reader.addEventListener('loadend', (e) => {
const text = e.srcElement.result;
console.log(text);
createCookie("myCookieCustom", text, "10");
});
});
});
and when I console.log the var "text" I get the html perfectly but it doesnt save in the createCookie function. I have tested "hello" instead of text in create cookie and that worked. Any idea how to solve this? just in case I am using the following functions to save and set cookies :
function createCookie(name, value, days) {
var expires;
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 4 * 1 * 1 * 1000));
expires = "; expires=" + date.toGMTString();
}
else {
expires = "";
}
document.cookie = escape(name) + "=" +
escape(value) + expires + "; path=/";
}
function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
}
else
{
begin += 2;
var end = document.cookie.indexOf(";", begin);
if (end == -1) {
end = dc.length;
}
}
// because unescape has been deprecated, replaced with decodeURI
//return unescape(dc.substring(begin + prefix.length, end));
return decodeURI(dc.substring(begin + prefix.length, end));
}
You can view the full html and css here in a w3 snippet I made : https://www.w3schools.com/code/tryit.asp?filename=GUCW5XSUMN1L and I am checking the cookie in php with (dont need help with php that I am fine with)
<?php
echo $_COOKIE["myCookieCustom"];
?>
Thanks in advance.