Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Js Ad Script

Status
Not open for further replies.

laffinos

Technical User
Nov 28, 2007
2
RO
I have a problem ...

I found yesterday this ad script, very nice,
But there ads appear after any refresh ...
I want, if i see the ad one time, next time when appear, after 24 hours ...
I think is possible whit cookies, but i don`t know how

Anyone can help me please ?

Thank you guys!
laffin
Reply With Quote
 
I think is possible whit cookies, but i don`t know how

You are correct. However, since there is countless information on javascript cookies spread throughout the internet I will just give you the basic idea of how to fix your problem. As for the specifics on how cookies work, I'd go ask everybody's good friend: google.


Now, after you have researched javascript cookies on google and found out how they work, this is going to be the basic premise to the solution:

1) When the page is loaded you initiate a getCookie function (you should be able to easily find one of these functions already coded for you on google). If the results from your getCookie function are null that means that the person has not yet visited this page today - so you want to invoke the ad code you stole borrowed from dynamic drive.

2) At the end of the code that displays the ad you'll want to invoke the setCookie function (again, another function you'll find on google) to signify that the user has already seen the ad.

3) Now, above you said something about 24 hours but it wasn't in a legible sentence - so I'm going to assume that you don't want the user to see the ad again for a 24 hour period, at which point they will then again see the ad. Cookies have a feature in the form of an expiration date. This allows you to specify a set amount of time that the cookie exists before it no longer becomes usable - refer to the documentation on the setCookie function to get the specifics. So, if you want the user to see the ad again after a 24 hour period, you'll need to set the expiration date exactly 1 day in the future. What this means from what I've described above is that when the getCookie function is invoked 24+ hours after the setCookie function was invoked, it will not find a valid cookie and the ad will be displayed again (at which point it set's a new cookie and the ad will not be displayed for another 24 hour period)

Hope that helps.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top