从Lotus Domino,Firefox&歌剧OK

时间:2011-08-22 12:34:24

标签: cookies lotus-domino lotus-formula

我在Lotus Domino应用程序中使用了一些旧但可行的javascript来设置会话和持久性cookie,它在Firefox和Linux中运行良好。 Opera但在IE8中不起作用。如果添加html来阻止IE缓存页面,但这没有任何区别。这是代码:

//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特有的,最奇怪的是我可以看到我在本地服务器上设置的一些cookie但是不能删除我在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这是我第一次看到javascript无法在IE中工作的问题当Mozilla中的相同代码工作时,我正在考虑的代码在IE5中是可以的,但现在在代码触发时不再有效IE的后期版本,有谁可以阐明这一观察结果?

9月16日 我在我的购物车上取得了很多进展,但现在上面的公式正在分解,而不是根据我所在的页面设置cookie。它与Firefox和Firefox中的相同歌剧。在查看葡萄酒时,我可以看到饼干。精神类别,但不是配件和礼品,但两种页面类型都使用相同的代码....

1 个答案:

答案 0 :(得分:0)

我已经找到了公式语言cookie代码的问题,经过一些调整后工作正常。最大的问题(未记录)是因为cookie最初存储在浏览器缓存中,所以只有在刷新时才会在加载的第一页上的http_cookie中看到cookie值。

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

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