Click to See Complete Forum and Search --> : pop-ups once per session


spacenuts
09-15-2003, 10:27 AM
Hi There,

I have a homepage and would like my JS to have the pop-up window only pop-up everytime a user launches his/her's browser, NOT once per day. The following code has the pop-up window pop-up once per day and not per session. Do you know how I can adjust this code so the pop-up pops-up once per session?? Thanks for your help!!

var expDays = 1; // number of days the cookie should last
var isPopUpWindowEnable = true; // Change to 'false' to diasable window popup and to 'true' to enable

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,expires) {
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 getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
if(isPopUpWindowEnable == false){
return
}
var count = GetCookie('poponce');
if (count == null) {
count++;
SetCookie('poponce', count, exp);

// Action to take
dothis()
}
}

function dothis(){
var windowprops = "left=50,top=50,width=285,height=240,location=no,toolbar=no,menubar=no,scrollbars=no"; window.open("/popup_wto.html", "", windowprops); // Use to load a page
}

//add onLoad="checkCount()" to the opening BODY tag

Khalid Ali
09-15-2003, 10:35 AM
what you can do is set a specific time for session to expire in cookies.

then was user browse through the pages update the timer on each page,and as soon as user closes or browse out from your pages after that time is up cookie will be automatically deleted.

requestcode
09-15-2003, 11:15 AM
Here is a link to a script that will only popup a window once per session. It pops up when they leave the page, but can easily be changed to popup when the enter.
http://www.javascriptkit.com/script/cut65.shtml