artsygal
08-23-2002, 02:50 PM
Good morning!
I am trying to create a survey for our intranet. A survey pop up box pops up when the homepage is opened. When the survey is submitted, a cookie is written to the users computer. This way the cookie is only written if the user submits the survey. (I got this much to work. I'm so proud!)
Now the hard part. The next time the user opens the homepage, I want the script on the homepage to look and see if there is a cookie. If there is no cookie, the survey should pop up again. If there is a cookie, no pop up! This is the part I can't get to work. Do you know of any scripts out there that I can look to as an example? This is what I've tried. I've tried cookie=="" as well. Thank you so much for any thoughts on this! --Leisa
To set the cookie, with function called using onmousedown for the submit button:
//This sets a cookie
function setcookie(){
var mydate=new Date();
//advancing the year by 1 to expire
mydate.setYear(mydate.getYear()+1);
document.cookie="name=mycookie;expires="+mydate.toGMTString();
}
To read the cookie and open/not open the window:
function openwin(){
if (document.cookie!=""){
winref=window.open("ContactManagerSurvey.htm", "newwin",
"width=380,height=450")
}
}
<body bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0" onLoad="openwin();" link="#000066" vlink="#000066" alink="#000033">
I am trying to create a survey for our intranet. A survey pop up box pops up when the homepage is opened. When the survey is submitted, a cookie is written to the users computer. This way the cookie is only written if the user submits the survey. (I got this much to work. I'm so proud!)
Now the hard part. The next time the user opens the homepage, I want the script on the homepage to look and see if there is a cookie. If there is no cookie, the survey should pop up again. If there is a cookie, no pop up! This is the part I can't get to work. Do you know of any scripts out there that I can look to as an example? This is what I've tried. I've tried cookie=="" as well. Thank you so much for any thoughts on this! --Leisa
To set the cookie, with function called using onmousedown for the submit button:
//This sets a cookie
function setcookie(){
var mydate=new Date();
//advancing the year by 1 to expire
mydate.setYear(mydate.getYear()+1);
document.cookie="name=mycookie;expires="+mydate.toGMTString();
}
To read the cookie and open/not open the window:
function openwin(){
if (document.cookie!=""){
winref=window.open("ContactManagerSurvey.htm", "newwin",
"width=380,height=450")
}
}
<body bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0" onLoad="openwin();" link="#000066" vlink="#000066" alink="#000033">