开发者

Cookies not working in IE from Lotus Domino, Firefox & Opera OK

I'm using some old but workable javascript in a Lotus Domino application to set a session and persistant cookie, it works fine in Firefox & Opera but isn't working in IE8. If added html to stop IE caching the pages but this made no difference. This is the code:

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

I don't think this is Lotus Domino specific, weirdest thing is that I can see some cookies that I have set on local server but can't delete these which I do seem to be able to do in Firefox, this is driving me nuts over last three days!!

Firefox debugger is not reporting any errors and neither is IE in debug mode.

Update - Later that day, no solution to problem with javascript code but the following formula in a computed field on the from sets a session cookie everytime, its native Lotus Formula language which I have a bit of a love-hate relationship with but in this case its very simple and 100% reliable!

@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)

p.s This is not the first time I've seen an issue with javascript not working in IE when the same code works in Mozilla, the code I'm thinking about was OK in IE5 but now no longer works when code triggered in later versions of IE, can anyone shed light on this observation?

16th Sept I made loads of progress on my shopping cart but now the above formula is breaking down and not setting a cookie depending on which page I'm on. Its the same in Firefox & Opera. I can see the cookies when开发者_Python百科 viewing wine & spirit categories but not accessories & gift items but same code is used for both page types....


I've figured out the problem with the formula language cookie code which after some tweaking is working ok. The biggest issue (undocumented) is that because cookies are initially stored in the browser cache you won't see the cookie value in http_cookie on the first page that loads, only when its refreshed.

The rest of the solution revolved around using webqueryopen agents to examine the http_cookie field and the computed cookie field and other browser related cgi fields to tell if the visit was from a search bot or a human as I don't need to worry about shopping carts for search bots.

I have to say that its been a frustrating exercise primarily because its so poorly documented, maybe Domino would have had (may still have) more milage for browser apps if there was better documentation and help available for domino application development. Its not put me off, but this time around I had the time to pursue it until a solution was found as it was a personal project rather than paid work for a client.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜