2014-09-24 64 views
0

我正在使用TideSDK为Windows开发桌面应用程序。我正在尝试使用cookie来存储用户在登录时输入的电子邮件地址的信息。我保存的电子邮件地址(在我的index.html文件中)的cookie会在下一页(mainMenu.html)加载时丢失。Javascript无法在Windows操作系统页面之间检索cookie

的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")); 

这是从我的mainMenu.html警报statment的样子:

enter image description here

为什么我的cookie不保存在文件之间?

预先感谢您!请让我知道,如果我太模糊或遗漏任何东西,我会很乐意解释自己! :)

回答