I am using TideSDK to develop a desktop app for windows. I am trying to use a cookie to store the information of the email address that a user enters on login. The cookie that I save for the email address (on my index.html file) somehow becomes lost when the next page (mainMenu.html) loads.
index.html Javascript:
//this is what I call when the login information is correct
function setCookie(cname,cvalue,exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires=" + d.toGMTString();
document.cookie = cname+"="+cvalue+"; "+expires;
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.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) != -1) return c.substring(name.length, c.length);
}
return "";
}
setCookie("email",em,30); //setting the cookie
window.location.href = "mainMenu.html"; // go to the next page
mainMenu.html Javascript:
//this is what I call when the page gets loaded
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.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) != -1) return c.substring(name.length, c.length);
}
return "";
}
alert("email: "+getCookie("email"));
This is what the alert statment from my mainMenu.html looks like:
Why is my cookie not saved between files?
Thank you in advance!!!! Please let me know if I was too vague or left anything out, I will gladly explain myself!!! :)
Since tidesdk is not properly a "browser" cookies may not work as expected. use a JSON structure to save such information. Please read the topic about your cookies here
TideSDK How to save a cookie's information to be accessed in different file?
Cookies may not be the best option for tidesdk to store information.