JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old November 26th, 2003, 08:47 PM
Alicia Alicia is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 116 Alicia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 27 m 49 sec
Reputation Power: 5
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.

Reply With Quote
  #2  
Old November 26th, 2003, 09:32 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
You aren't too far off - definately got the logic right.

Change where you have:
Code:
form2.cookie = "cookieName=cookieValue";
to:
Code:
 document.cookie = "visited=true";
You also need to add some code to read your cookie values. For some reason a cookie handling library was not included in Javascript. Copy this function and place it in the HEAD of your file.
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;
}
Then, to check the value of the cookie when the users hits your page, use the code
Code:
if (readCookie("visited")) {
   // user has been here before
}
else {
   // user has NOT been here before
}
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #3  
Old November 26th, 2003, 10:38 PM
Alicia Alicia is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 116 Alicia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 27 m 49 sec
Reputation Power: 5
thank you very much stumpy

Reply With Quote
  #4  
Old May 18th, 2004, 12:51 PM
Susan0722 Susan0722 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 4 Susan0722 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!

Reply With Quote
  #5  
Old May 18th, 2004, 06:45 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
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).

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > set cookie in a page


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway