cookies in Javascript and ASP

T

tanya.wang

Hi all,

I wanna create a new notes reminder system in my website. Everytime
when a user logs in he would receive a small piece of alert. He will
kept receiving it until he either logoff or "chooses to close it".
Once it's closed, the alert is turned off. So I embeded this piece of
my program in a header file that would be called by every of my
webpage myheader.asp

<!--#include file="myheader.asp"-->

In myheader.asp I called another program mynotice.asp to see if a user
will receive a small alert of new notice. Once he chooses not to
receive, a cookie will be set and the alert will never be loaded.

Here is what I put in myheader.asp... the request.cookies("isLogin")
was set by ASP when the user is logged in.

<% if request.cookies("isLogin")="OK" and
request.Cookies("readNotice")<>"1" then %>
<!-- #include file="mynotice.asp" -->
<% end if %>

Here is what I do in mynotice.asp

<DIV id="myNoticePop">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
<TR><TD><img src="../images/CancelNotice.gif"
onclick="ClosePopup()"></TD>
</TR>
</TABLE>
</DIV>

<script language=javascript>
var ThePop = document.getElementById("myNoticePop").style;

function setCookie(NameOfCookie, value, expiredays)
{
var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 *
1000));
document.cookie = NameOfCookie + "=" + escape(value) +
((expiredays == null) ? "" : "; expires=" +
ExpireDate.toGMTString());
}
function ClosePopup(){
ThePop.visibility = "hidden";
setCookie("readNotice",1,1);
}
</script>

Here comes my question -
My asp pages cannot tell the request.Cookies("readNotice") which was
set up by javascript. If I triggered the closePopup(), and switch to
another page, it will still run into the mynotice.asp unless I refresh
my current page.
But what I really want is to remember if a user has clicked the
closePopup() during his login. If so then turn off the alert. When he
log off this cookie things should be cleared.

Could anyone tell me why my cookies cannot be read by asp? Or should I
abort using cookie for this function and use something else instead?
 
A

Anthony Jones

Hi all,

I wanna create a new notes reminder system in my website. Everytime
when a user logs in he would receive a small piece of alert. He will
kept receiving it until he either logoff or "chooses to close it".
Once it's closed, the alert is turned off. So I embeded this piece of
my program in a header file that would be called by every of my
webpage myheader.asp

<!--#include file="myheader.asp"-->

In myheader.asp I called another program mynotice.asp to see if a user
will receive a small alert of new notice. Once he chooses not to
receive, a cookie will be set and the alert will never be loaded.

Here is what I put in myheader.asp... the request.cookies("isLogin")
was set by ASP when the user is logged in.

<% if request.cookies("isLogin")="OK" and
request.Cookies("readNotice")<>"1" then %>
<!-- #include file="mynotice.asp" -->
<% end if %>

Here is what I do in mynotice.asp

<DIV id="myNoticePop">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
<TR><TD><img src="../images/CancelNotice.gif"
onclick="ClosePopup()"></TD>
</TR>
</TABLE>
</DIV>

<script language=javascript>
var ThePop = document.getElementById("myNoticePop").style;

function setCookie(NameOfCookie, value, expiredays)
{
var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 *
1000));
document.cookie = NameOfCookie + "=" + escape(value) +
((expiredays == null) ? "" : "; expires=" +
ExpireDate.toGMTString());
}
function ClosePopup(){
ThePop.visibility = "hidden";
setCookie("readNotice",1,1);
}
</script>

Here comes my question -
My asp pages cannot tell the request.Cookies("readNotice") which was
set up by javascript. If I triggered the closePopup(), and switch to
another page, it will still run into the mynotice.asp unless I refresh
my current page.
But what I really want is to remember if a user has clicked the
closePopup() during his login. If so then turn off the alert. When he
log off this cookie things should be cleared.

Could anyone tell me why my cookies cannot be read by asp? Or should I
abort using cookie for this function and use something else instead?

Have you considered using a session variable?

Also consider ditching the annoying popup and replace it with something more
subtle such as a 'New Notice' icon in the header bar on the page(s).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top