#1 (permalink)  
Old 10-26-2010, 04:51 PM
Jim Poor's Avatar
Class Curmudgeon
 
Join Date: Nov 2008
Location: Northern VA
Posts: 3,501
Default How to create JS message with cookie

I had one a while back but can't find it now.

I need to put a "We'll be closed" message on my site that only pops up once per day or even once every two days for each visitor.

Right now, what I have pops up every visit, which could get rather annoying.

See what I have here: Jim Poor Photography

Anyone know how to add a cookie to it so it only pops up once per day or every two days?
__________________
Best,
Jim
Facebook
Visit my website
Reply With Quote
  #2 (permalink)  
Old 10-26-2010, 05:02 PM
Jim Bryant's Avatar
Stoned Cold Crazy
 
Join Date: Dec 2008
Location: WA
Posts: 8,084
Default

Wish I knew too. Guess that's what we get for having opinions and giving out free advice.
__________________
url:www.jimbryantphotography.com
http://pa.photoshelter.com/c/jimbryant
http://jimbryantphotography.blogspot.com/
(3) EOS1D MKIIs', (1) EOS1Ds MKII, 14mmf2.8, 16-35mmf2.8, 28-70mmf2.8, 70-200mm f2.8, 300mm f2.8 and a 400mmf2.8.
Reply With Quote
  #3 (permalink)  
Old 10-26-2010, 05:06 PM
lputman's Avatar
Super Moderator
 
Join Date: Apr 2008
Location: Olive Branch, MS
Posts: 7,325
Default

I'm not a coder, but this might help, pop up only once??? - CodingForums.com
__________________
Lori Putman flickr
~No one can drive us crazy unless we give them the keys
~~Life isn't about waiting for the storm to pass, it's about learning to dance in the rain!
7D | 300L f/4 IS | 135L | 35L | 100/2.0 | 50/1.4
430 EX, 580 EX II Speedlites
Reply With Quote
  #4 (permalink)  
Old 10-26-2010, 05:07 PM
Jim Poor's Avatar
Class Curmudgeon
 
Join Date: Nov 2008
Location: Northern VA
Posts: 3,501
Default

Thanks. I found that one, but reading through it made my head spin
__________________
Best,
Jim
Facebook
Visit my website
Reply With Quote
  #5 (permalink)  
Old 10-26-2010, 05:08 PM
BuddhaPi's Avatar
Middle School Graduate
 
Join Date: May 2010
Location: Jupiter, Florida
Posts: 1,605
Default

try this...Paste this code into an external ********** file named: onlyPopupOnce.js

var expDays = 1; // number of days the cookie should last

var page = "only-popup-once.html";
var windowprops = "width=300,height=200,location=no,toolbar=no,menuba r=no,scrollbars=no,resizable=yes";

function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}

function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt(){
var count = GetCookie('count')
if(count == null) {
SetCookie('count','1')
return 1
} else {
var newcount = parseInt(count) + 1;
DeleteCookie('count')
SetCookie('count',newcount,exp)
return count
}
}

function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
var count = GetCookie('count');
if (count == null) {
count=1;
SetCookie('count', count, exp);
window.open(page, "", windowprops);
} else {
count++;
SetCookie('count', count, exp);
}
}

window.onload=checkCount;

Then, paste this code into the HEAD section of your HTML document.


******** type="text/**********" src="onlyPopupOnce.js">***********
__________________
Nikon D7000:18-105mm VR Kit, Nikkor 35-70mm 2.8AF, Nikkor 50mm f/1.8d AF, Sigma 150-500mm f/5-6.3 AF, SB600
Web Design of Palm Beach
Photo Blog
Become a Fan on Facebook
Reply With Quote
  #6 (permalink)  
Old 10-26-2010, 05:10 PM
BuddhaPi's Avatar
Middle School Graduate
 
Join Date: May 2010
Location: Jupiter, Florida
Posts: 1,605
Default

i'm sure "someone" else will have a better answer...
__________________
Nikon D7000:18-105mm VR Kit, Nikkor 35-70mm 2.8AF, Nikkor 50mm f/1.8d AF, Sigma 150-500mm f/5-6.3 AF, SB600
Web Design of Palm Beach
Photo Blog
Become a Fan on Facebook
Reply With Quote
  #7 (permalink)  
Old 10-26-2010, 05:26 PM
dPS +1000 Club
 
Join Date: Jul 2009
Posts: 1,863
Default

I just remembered why I employ programmers to do my stuff
Reply With Quote
  #8 (permalink)  
Old 10-26-2010, 06:58 PM
Mr Guy's Avatar
dPS +1000 Club
 
Join Date: Apr 2008
Location: Raleigh, NC
Posts: 1,566
Default

I can help you with that, if you haven't already solved it.

Conceptually, you need to store the date as your cookie, and then find the differences between both dates, and do modulus math, and only pop it up when the modulus math comes out 0.

Taking a quick look at your site to give specific advice.

*Edit*

Yeah, I thought you meant you had it working but it was popping up too often. The code posted above ought to be very close to what you need, except for:
Code:
window.open(page, "", windowprops);
which you'll need to replace with your alert.
__________________

But Mom, Pentax IS rebellious
Pentax K-7, K20D
Pentax SMCP-FA 35mm f/2.0 AL -- Pentax SMC 50mm f/1.7 -- Pentax DA 50-200mm f/4-5.6 ED -- Sigma 28-70mm f/2.8 EX DG IF Aspherical -- Pentax DA 18-55mm f/3.5-5.6 WR

Last edited by Mr Guy; 10-26-2010 at 07:03 PM.
Reply With Quote
  #9 (permalink)  
Old 10-26-2010, 07:00 PM
Jim Poor's Avatar
Class Curmudgeon
 
Join Date: Nov 2008
Location: Northern VA
Posts: 3,501
Default

Quote:
Originally Posted by BuddhaPi View Post
i'm sure "someone" else will have a better answer...

Thanks. That's the code that confused the crap out of me.

The last one I had, I only had to paste the code into my footer (to load after the site) and there was no reference to an external doc.

I know I saved it but just can't remember where or what the file was called. :-(
__________________
Best,
Jim
Facebook
Visit my website
Reply With Quote
  #10 (permalink)  
Old 10-26-2010, 07:08 PM
inkista's Avatar
Gear Geek Girl
 
Join Date: Jan 2007
Location: San Diego, CA
Posts: 9,154
Default

Just a sidenote, but could one of the mods/admins PLEASE remove the word that JS stands for from the censorship list? It's not that funny, and it's freaking annoying that everytime you type in ********** the damn word gets asterisked out. Especially with code examples, or when you're asking for website help.
__________________
I shoot with a Canon 5DmkII, 50D, and S90, and Pansonic G3. flickr stream and equipment list
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are Off



Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

What’s Your Preference?

Daily Digest

Each day we send out a quick email to thousands of DPS readers to notify them of updates. This email is just short excerpt of the first few lines of our latest post with a link if you want to read it all. You can unsubscribe from this this service at any time.

This service is provided by a third party (Feedburner) and you can subscribe to it by leaving your email address in the following field and confirming your subscription when you get an email asking you to do so.

Enter your email address for
Daily Updates:

Weekly Summary

For those wanting a weekly summary of what happens on this site this free email newsletter is probably your best option. It includes a summary of the tips posted to the site each week. This newsletter is subscribed to by over 25000 readers (many who also subscribe to the other options above) - come join the community!

To subscribe to this weekly newsletter simply add your email address to the following field and then follow the confirmation prompts. You will be able to unsubscribe at any time.

Enter your email address for
Free Weekly Newsletter:

 
SEO by vBSEO 3.3.0