|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
set cookie in a page
Hi guys,
currently i have a page where once it loads, the popup window will appear.. i am wondering is there anyway i can make it pop up only in the users first visit ? that means if the user press back, the pop up will not appear ? p.s: my idea is to use cookie, but how can i do that ? i tried to use this code but it doesn;t work... my code: if(cookieName ="") { window.open('popup.htm','','menubar=no,resizable=y es,width=430,height=580'); } function xitpop() { if (exit) { form2.cookie = "cookieName=cookieValue"; window.open("http://www.myweb.com/exit_popup.htm","sample","height=500,width=604,status=yes,menubar=no,locatio n=no,resizable=no,titlebar=yes,scrollbars=yes,top= 50,left=50"); } } // in onunload, my code will refer to xitpop() function. Why this is not working ?? or do you guys have any better idea how to accomplish this task ? Please advise. |
|
#2
|
||||
|
||||
|
You aren't too far off - definately got the logic right.
Change where you have: Code:
form2.cookie = "cookieName=cookieValue"; Code:
document.cookie = "visited=true"; Code:
function readCookie(name)
{
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++)
{
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
Code:
if (readCookie("visited")) {
// user has been here before
}
else {
// user has NOT been here before
}
|
|
#3
|
|||
|
|||
|
thank you very much stumpy
![]() |
|
#4
|
|||
|
|||
|
Hi Everyone, I am new to this forum, found in a Google search.
I am currently doing a contest on my website where I will be asking the public to vote on new baby horses. I would like very much to set it so when they make their votes, that they will not be allowed to vote again so to avoid anyone trying to stuff the ballot box. I use Front Page and I currently have my form info collected to a database. If possible I would also like to be able to show current votes on any particular foal. This is the page I am working with, it is currently not available for public view or voting, but is online so I can get some help. http://www.horseplaycentral.com/newfoals2004/2004foalsvoting2.asp I am thinking I just need to set a cookie in the page that will tell the database that person has already voted and are not allowed to vote again. Or someone else suggested I have the datatbase read the ip address and block it that way.........right now the database does capture the ip address but how do I tell it not to let this same person vote again? Thank you in advance, for your help from this NON ASP person, who is trying something new! |
|
#5
|
||||
|
||||
|
Hey Susan,
I would guess that for your users and purpose, it would be sufficient to just set a cookie. Setting cookies via ASP is quite simple - a great place to learn how to use them is w3Schools: http://www.w3schools.com/asp/asp_cookies.asp After the user submits their vote, set a cookie with a suitable expiry date (say, until you next plan on having a poll). |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > set cookie in a page |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|