Cookie 在 Lotus Domino、Firefox 和 IE 中不起作用歌剧OK
我在 Lotus Domino 应用程序中使用一些旧的但可行的 javascript 来设置会话和持久 cookie,它在 Firefox 和 Firefox 中运行良好。 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,但无法删除这些cookie,而我似乎能够在Firefox中做到这一点,过去三天这让我发疯!
Firefox 调试器没有报告任何错误,IE 也没有处于调试模式。
更新 - 那天晚些时候,没有解决 javascript 代码问题,但每次都会在计算字段中设置一个会话 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 中是可以的,但现在当代码在更高版本中触发时不再工作即,任何人都可以阐明这一观察结果吗?
9月16日 我在购物车上取得了很大的进展,但现在上面的公式被打破了,并且没有根据我所在的页面设置 cookie。在 Firefox 和 Firefox 中也是如此。歌剧。我在观看葡萄酒和葡萄酒时可以看到饼干。烈酒类别,但不包括配件和酒类礼品,但两种页面类型使用相同的代码......
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 viewing wine & spirit categories but not accessories & gift items but same code is used for both page types....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经解决了公式语言 cookie 代码的问题,经过一些调整后可以正常工作。最大的问题(未记录)是,由于 cookie 最初存储在浏览器缓存中,因此只有在刷新时,您才不会在加载的第一个页面上看到 http_cookie 中的 cookie 值。
解决方案的其余部分围绕使用 webqueryopen 代理来检查 http_cookie 字段和计算的 cookie 字段以及其他浏览器相关的 cgi 字段来判断访问是来自搜索机器人还是人类,因为我不需要担心购物车用于搜索机器人。
我不得不说,这是一项令人沮丧的工作,主要是因为它的文档记录非常少,如果有更好的文档和可用于 domino 应用程序开发的帮助,也许 Domino 浏览器应用程序会有(可能仍然)更多的里程。这并没有让我失望,但这一次我有时间去追求它,直到找到解决方案,因为这是一个个人项目,而不是为客户付费的工作。
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.