2011-08-22 69 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可能已經(可能還會有)更多的瀏覽器應用程序。它並沒有讓我失望,但這次我有時間去追求它,直到找到解決方案,因爲這是一個個人項目,而不是爲客戶付費。

相關問題