2014-02-28 4 views
-2

어떻게이 코드에 다른 페이지를 방문한 후에 다시 나타나지 않고 되돌아가는 쿠키가 있습니까? 나는() 이벤트 코드 here클릭하면 쿠키가 누락됩니다.

 <script type="text/javascript"> 

function toggle_text(shown, hidden) { 
     var e = document.getElementById(shown); 
     var f = document.getElementById(hidden); 
    if(e.style.display == 'inline') { 
        e.style.display = 'none'; 
        f.style.display = 'inline'; 
     } 
     else { 
        e.style.display = 'inline'; 
        f.style.display = 'none'; 
     } 
} 
</script> 
    <div id="shown_first" style="display:inline"> 
     <a style="cursor:pointer" onclick="toggle_text('shown_first', 'hidden_first')"> 
     <a href="/popular.html" style="text-decoration:none;"><i> New! </i> Vote for Websites Here</a. 
     </a> 
</div> 
<div id="hidden_first" style="display:none"> 
     <a style="cursor:pointer" onclick="toggle_text('shown_first', 'hidden_first')"> 

     </a> 
</div> 
+1

_ "이 코드에 설정된 쿠키가 있습니까?"- 먼저 해당 항목에 대해 _research_를 수행하면 어떻게됩니까? – CBroe

+0

크 브로 저는 시간이 없습니다. – Wai

+1

아무 때나 압박감을 느끼는 사람은 아무도 없습니다. 숙제를 가지고 머리 위로 들어갔다면 그건 완전히 유일한 문제입니다. – CBroe

답변

1

나는 귀하의 질문에 제대로, 당신은 window.onunload에 이벤트를 묶어 필요가 이해한다면있어 어디에 있는지 또한 onlythebestoftheweb.x10.mx

라이브 버전을 참조하는 당신이 찾고있는 쿠키를 제거합니다.

html로 -

<body onunload="deleteCookie()"> 

자바 스크립트 -

window.onunload=function(){ 
    // Get cookie 
    // Set cookie expiration to yesterday 
}; 

페이지는으로 onUnload 이벤트를 호출합니다 닫습니다. 이 경우 원하는 쿠키를 얻은 다음 그 값을 어제로 설정하면 쿠키가 만료되어 브라우저에서 제거됩니다.

+0

내 코드에 붙여 넣기 만하면됩니까? 왜냐하면 내가 그 일을했을 때 일을하지 못했기 때문이야 ... 텍스트는 홈 페이지로 돌아 갔을 때 거기에있었습니다. – Wai

+1

쿠키를 가져오고 쿠키를 설정한다고하는 곳. document.cookie = "yourcookiename =; 만료 = 1970 년 1 월 1 일 00:00:00 GMT"; 그러면 cookie yourcookiename이 생성되고 만료 날짜가 설정됩니다. w3schools 웹 사이트에서 바로 가져 왔습니다. 효과가있는 경우 올바르게 표시 하시겠습니까? – VtoCorleone

관련 문제