2011-08-22 70 views
0

我在Lotus Domino应用程序中使用了一些旧的但可行的JavaScript来设置会话和持续性cookie,它在Firefox中工作正常& Opera但无法正常工作在IE8中。如果添加html来阻止IE缓存页面,但这没有什么区别。这是代码:Cookie在Lotus Domino,Firefox和Opera的IE中不起作用OK

//Persistant and session cookies for shopping cart and 
//returning user identification 
function makeCartID() { 
    var part1 = Math.floor(Math.random()*900) + 1000; 
    var part2 = Math.floor(Math.random()*90) + 100; 
    return part1.toString() + "-" + part2.toString(); 
} 

//Math.ceil vs Math.floor, document these 
function rand(number) { 
    return Math.ceil(Math.random()*number); 
} 

// Function to return the value of the cookie specified by "name". 
// returns a String object containing the cookie value, or null if cookie not found 
function getCookie (name) { 
    var arg = name + "="; 
    var alen = arg.length; 
    var clen = document.cookie.length; 
    var i = 0; 
    while (i < clen) { 
    var j = i + alen; 
    if (document.cookie.substring(i, j) == arg) 
     return getCookieVal (j); 
    i = document.cookie.indexOf(" ", i) + 1; 
    if (i == 0) break; 
    } 
    return null; 
} 

// Persistent cookie for unique visitors and latent purchases 
function setCustCookies() { 
    var thisCookie = getCookie("fwc_shop"); 
    var myValue = thisCookie; 
    if(thisCookie == null) { 
     //Setup the random cookie value 
//  myValue = new Date(); 
//  var randNum = rand(100); 
     myValue = makeCartID(); 

     //The expiry date will be 5 years for production 
     //Starting with 1 day ... 
     var expiryDate = new Date(); 
    // expiryDate.setDate(expiryDate.getMonth() + 1); 
     expiryDate.setDate(expiryDate.getDay() + 1); 
     setCookie("fwc_shop", myValue, expiryDate, "/"); 
    }  

    // Session cookie for shopping cart, 15 minute default 
    var minutes = 15; //Testing, 60+ for production 
    var session = getCookie("fwc_cart"); 
    var scdt = new Date(); 
    var sdt = new Date(scdt.getMilliseconds + (minutes * 60 * 1000)); 

    var sessionVal; 
    if(session==null){ 
     sessionVal=myValue + "=" + scdt.toGMTString() + "_" + rand(100); 
    }else{ 
     sessionVal=session; 
    } 
    setCookie("fwc_cart", sessionVal, sdt, "/"); 
} 
setCustCookies(); 


// Function to delete a cookie. (Sets expiration date to current date/time) 
function deleteCookie (name) { 
    var exp = new Date(); 
    exp.setTime (exp.getTime() - 1); 
    var cval = getCookie (name); 
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString(); 
} 
//Worth a try from within script library!! 
deleteCookie("fwc_persist"); 

我不认为这是Lotus Domino的具体,最奇怪的是,我能看到我的本地服务器上设置一些饼干,但不能删除这些,我似乎确实能够在Firefox中做到这一点,这让我在过去三天中疯狂!

Firefox调试器不报告任何错误,IE也不处于调试模式。

更新 - 那天晚些时候,没有解决JavaScript代码问题的方法,但在from的计算字段中的下列公式每次都会设置一个会话cookie,其原生的Lotus Formula语言中我有一点爱恨关系但在这种情况下,它非常简单并且100%可靠!

@If(@BrowserInfo("Cookies");""; @Return("Error: cookies not enabled.")); 
cookieName:="session"; 
part1 := @Text(@Round(1000 * @Random)); 
part2 := @Text(@Round(10000 * @Random)); 
cookieValue:= part1 + "-" + part2; 
result:=cookieName + "="+ cookieValue + ";"; 
@SetHTTPHeader("Set-Cookie"; result) 

PS这不是我第一次看到的时候用相同的代码在Mozilla的JavaScript工作不工作在IE的问题,我想代码在IE5确定,但现在不再起作用当在IE的更高版本中触发代码时,是否有人能够阐明这一观察?

2016年9月16日 我在购物车上加载了大量的进度,但现在上面的公式正在崩溃,而不是根据我所在的页面设置cookie。它同样在Firefox & Opera中。观察酒&精神类而不是配件&礼品,但相同的代码同时用于页面类型时,我可以看到饼干....

+0

无法看到应用于用javascript设置的cookie的cookie值的问题,一旦我了解如何使用特殊的http_cookie字段查看已设置的cookie的进度相当快:) – AndrewB

回答

0

我已经想通了这个问题用公式语言Cookie代码后,一些调整工作正常。最大的问题是(无文档),因为cookie最初存储在浏览器缓存中,所以只有在刷新页面时,才会在加载的第一页上看到http_cookie中的cookie值。

解决方案的其余部分围绕使用webqueryopen代理来检查http_cookie字段和计算的cookie字段以及其他浏览器相关的cgi字段,以判断访问是来自搜索bot还是人类,因为我不需要担心搜索机器人的购物车。

我不得不说它是一个令人沮丧的练习,主要是因为它的记录太糟糕了,如果有更好的文档和可用于多米诺骨牌应用程序开发的帮助,Domino可能已经(可能还会有)更多的浏览器应用程序。它并没有让我失望,但这次我有时间去追求它,直到找到解决方案,因为这是一个个人项目,而不是为客户付费。

相关问题