2010-05-14 1 views
1

를, 즉 단순히 늘 내가 다른 이벤트를 통해 진정한 쿠키를 설정하고 8자바 스크립트 쿠키 문제가 일부 자바 스크립트를 통해 내 머리를 포기할 된

를 IE 7에서 내 쿠키를 찾거나 내가 왜 볼 수 없습니다, 도움이되지만 그냥하시기 바랍니다 IE가 처음에 설정 한 쿠키를 가져 오는 것을보고 싶습니다. 파이어 폭스에서도 작동합니다. 미리 감사드립니다.

var t=setTimeout("doAlert()",8000); 
var doAlertVar = true; 
document.cookie = "closed=0;expires=0;path="; 

function readCookie(name) { 
    var nameEQ = name + "="; 
    var ca = document.cookie; 
    alert(ca); 
    ca = ca.replace(/^\s*|\s*$/g,''); 
    ca = document.cookie.split(';'); 

    for(var i=0;i < ca.length;i++) { 
     var c = ca[i]; 
     while (c.charAt(0)==' ') c = c.substring(1,c.length); 
     if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); 
    } 
    return null; 
} 

function doAlert(){ 

    if(readCookie('closed')==1){ 
     doAlertVar = false; 
    } 
    if(readCookie('closed')==0){ 
     alert("unlicensed demo version\nbuy online at"); 

    } 
    t=setTimeout("doAlert()",5000); 

} 
+0

정확하게 당신이 보는 무엇을? 무엇이 언제 알려 지나요? 너는 무엇을 기대하고 있니? – Dan

+0

Javascript의 시작점 ('closed = 0;')에 추가 한 쿠키가 표시되지 않습니다. HTTP 요청을 통과 할 수있는 것은 – blakey87

답변

1

시작 ..

setTimeout("doAlert()",8000); 
// do not use strings as an argument to setTimeout, that runs eval under the hood. 
// use 
setTimeout(doAlert,8000); 
// instead 

document.cookie = "closed=0;expires=0;path="; 
// this is wrong, expires should follow the format Fri, 14 May 2010 17:22:33 GMT (new Date().toUTCString()) 
// path should be path=/ 
0

또한 정규식으로이 작업을 수행 할 수 있습니다

function readCookie(name, defaultValue) { 
    var value = defaultValue; 
    document.cookie.replace(new RegExp("\\b" + name + "=([^;]*)"), function(_, v) { 
    value = v; 
    }); 
    return value; 
} 
관련 문제