I trying Window.unload=setcookie(username,'xyz',365); where

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

not working.......
can anybody help me?

Recommended Answers

All 2 Replies

AFAIK, there is no reliable way of capturing the page unload event hence not possible. The maximum you can do is come up with some browser specific mumbo jumbo which would surely fail in other browsers. The only reliable way is to keep sending postbacks to the server using Ajax i.e. making an Ajax call every ten seconds / one minute with the updated values.

Since it seems that you are trying to set non-dynamic values (username), a even better way would be to set the Cookies on page load.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.