/    Sign up×
Community /Pin to ProfileBookmark

session cookies

are session cookies mainly made with vbs and if not can they be made using javascript? If so, anyone got a script handy or a link to learn from?

regards

Code One

P.s. I guess I outta tell you how I would like to use this script, I would like to allow for popup windows to popup once a session, even if the user reloads the page.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@96turnerriNov 23.2003 — you best bet is to modify this script which is one time only popup need to add code to delete cookie on window close

[code=php]
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
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,menubar=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);
}
}
</script>

<BODY OnLoad="checkCount()">
[/code]
Copy linkTweet thisAlerts:
@ray326Nov 23.2003 — Check a Javascript DOM reference for document.cookie.

http://www.javascriptkit.com/javatutors/cookie2.shtml seems to have a bunch of info on it.
Copy linkTweet thisAlerts:
@Code_OneauthorNov 24.2003 — thank you both for the script and tutorial!!!

regards

Code One
Copy linkTweet thisAlerts:
@Code_OneauthorNov 24.2003 — asks if I want to delete cookies onload of the page, but how do I change it to ask onunload of page, here's my code:

[code]
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
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,menubar=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);
}
}
[color=red]
if (document.cookie != "") {
if (confirm("Do you want to delete the cookies?")) {
thisCookie = document.cookie.split("; ")
expireDate = new Date
expireDate.setDate(expireDate.getDate()-1)

for (i=0; i<thisCookie.length; i++) {
cookieName = thisCookie[i].split("=")[0]
document.cookie = cookieName + "=;expires=" + expireDate.toGMTString()
}

}
}
[/color]
</script>

<BODY
Copy linkTweet thisAlerts:
@96turnerriNov 24.2003 — theres a script for deleting cookie on script i gave your try this inthe <body> onunload="DeleteCookie(name)"
Copy linkTweet thisAlerts:
@ray326Nov 24.2003 — A cookie created without an expiration date is by definition a "session cookie" and will be deleted when the browser is closed. I.e., you don't have to worry about deleting a session cookie.
×

Success!

Help @Code_One spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...