2014-02-28 48 views
-2

我該如何讓這段代碼有一個cookie,使得它在訪問另一個頁面後不會再出現並返回到它?見真人版在onlythebestoftheweb.x10.mx點擊使用Cookie消除點擊

也看到我的代碼 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

_「我如何讓這段代碼有一個cookie」_--通過對該主題進行一些_research_首先...? – CBroe

+0

cbroe我沒有時間爲 – Wai

+1

沒有人_cares_如果你在任何時間的壓力。如果你的任務是完成任務,那純粹是單純的_你的問題。 – CBroe

回答

1

如果我理解你的問題正確的話,你需要配合一個事件到window.onunload有()事件刪除你正在尋找的任何cookie。

的Html -

<body onunload="deleteCookie()"> 

的JavaScript -

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

當頁面關閉它會調用onunload事件。在這種情況下,您將得到您要查找的cookie,然後將該值設置爲昨天,以便cookie將過期並從瀏覽器中刪除。

+0

我只是將粘貼到我的代碼?因爲當我這樣做,它沒有工作......當回到主頁時,文本留在那裏。 – Wai

+1

它說,得到cookie和設置cookie ....添加此代碼 document.cookie =「yourcookiename =; expires =星期四,1970年1月1日00:00:00 GMT」; 這將獲得Cookie yourcookiename並將日期設置爲過期日期。從w3schools網站上正確使用。 如果它適合你,你會標記這個正確的嗎? – VtoCorleone