View Full Version : Creating Popup cookies
SWiSHSource.com
09-04-2002, 01:35 PM
When someone enters my site a popup comes up on the page. I only want this to come up once per person. How would I go about doing this? Thanks! Michael :)
Oh, and one more thing, this popup window script is giving me problems because it loads before my page loads, so it slows down the page opening.
<script>
<!--
function newWin(){
window.open('http://www.freelayouts.com/cgi-bin/arp/rankem.cgi?id=michael','myWin','width=600,height=600,toolbar=no,scrollbars=yes status=yes,top='+((screen.height-400)/2)+',left='+((screen.width-475)/2));
}
setTimeout("newWin()",500); //workaround for ie4 new window focus bug.
//-->
</script>
Is there anything that can be done with this? Thanks, Michael
I have just posted a response to dean about cookie so you might as well have a copy of this as well.
It is a cookie that only pops once and you can set the days as well.
SWiSHSource.com
09-04-2002, 09:40 PM
Thank you so Much! But, just a few questions: I dont know what you mean when you say I have to put my statement here in the function dothis() What do I put there? And is this all of the editing I need to do with this? Sorry, not too familiar with JS, just learning it. :)
Thanks again! Michael
Take a look at the source for the poponce script
Near the bottom of the script you will see a call for function dothis()
dothis()
}
else {
count++;
SetCookie('count', count, exp);
}
}
// End -->
</script>
Near the top of the script you will see the function:
function dothis(){
YOUR STATEMENTS GO HERE
WHAT YOU WANT TO HAPPEN THE FIRST TIME THE COOKIE IS CALLED
}
Change this function for your function, and change the call to dothis() to call your function
As for the popup problem you have set the delay for 500 milliseconds if the popup is opening too early the use a longer delay try 3000 (3 seconds)
SWiSHSource.com
09-05-2002, 04:40 AM
You fixed my popup problem, thank you!!! But, I'm such a retard, I still dont understand what I'm supposed to do in side the function....... What do I do there? Thanks again! Michael
The purpose of the cookie is to run a function once in a set period of time.
So if you want a popup window then the function dothis() would be replaced by:
function popup(){
window.open("page.htm",'win1','width=300,height=300,left=300,top=200')
}
if you want to play a sound:
function playsound(){
Blah Blah Blah
}
etc. etc.
SWiSHSource.com
09-07-2002, 04:33 PM
I got it to work!! Thanks! But, when I delete my cookies and tried it again, it poped up with a whole bunch of other popups, is this because of the cookie script? When I go to the FreeLayouts.com, it doesnt have any popups on that page so I know it is not that. :confused:
Thanks again! Michael
<SCRIPT LANGUAGE="JavaScript">
<!--
var expDays = 1; // number of days the cookie should last
function popup1(){
window.open("http://www.freelayouts.com/cgi-bin/arp/rankem.cgi?id=michael",'win1','width=600,height=600,left=100,top=100,toolbar=no,scrollbars=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] : null;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == null) ? "; 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);
popup1()
}
else {
count++;
SetCookie('count', count, exp);
}
}
// End -->
</script>
I should only delete that cookie when testing otherwise other scripts relying on their cookies will reactivate.
SWiSHSource.com
09-07-2002, 04:52 PM
I dont understand.... So what should i do?
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.