English 中文(简体)
单击以隐藏会话的 div 显示
原标题:Click to hide a div for session

我正把一个小盒子放在我的页面上,我想在有人来时出现,但是当他们点击近距离时,就会消失在他们的会话上。现在我...

<script language="JavaScript">
function setVisibility(id, visibility) {
document.getElementById(id).style.display = visibility;
}
</script>

然后干脆把Div和...

onclick="setVisibility( divname ,  none );

但这是每页。我还能添加或修改什么来设置它,以便一旦他们点击关闭,它不会回来,直到他们与网站的会话结束为止?

谢谢 谢谢

edit: I am using php. 谢谢 谢谢 for the answers so far, can anyone point me in a direction to add the cookies?

最佳回答

使用此函数创建 cookie 。 当用户隐藏 div 时, 请调用它 。

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

然后在每一页上加上这个:

function checkCookie()
{
var username=getCookie("username");
  if (username!=null && username!="")
  {
  alert("Welcome again " + username);
  }
else
  {
  username=prompt("Please enter your name:","");
  if (username!=null && username!="")
    {
    setCookie("username",username,365);
    }
  }
}

并检查他们是否关闭了 div 。 这些是直接的节录。 您必须修改以适应您的要求。 这只是可以使用的流。

问题回答

您可以在点击接近时在 Javascript 中设置会话 cookie, 并总是对照 cookie 的存在( 或值) 检查 。

(在此情况下不需要服务器侧面)





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签