我在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中。观察酒&精神类而不是配件&礼品,但相同的代码同时用于页面类型时,我可以看到饼干....
无法看到应用于用javascript设置的cookie的cookie值的问题,一旦我了解如何使用特殊的http_cookie字段查看已设置的cookie的进度相当快:) – AndrewB