View Full Version : How can I get a cookie to open pop-up window once only per session visit?

08-02-2002, 07:37 PM
A friend of mine gave me this bit of script, I spent hours and hours trying to get it working. He claims it works on his PC fine (WIN 2000 with IE6) but it don't work on mine (Win 95 IE4)

The problem is:
If the line if(document.cookie=="") is left as
is, nothing happens and there is no cookie
in the temp. internet files folder.

If that line is changed to if(document.cookie!="")
then the cookie appears in the temp. internet files
folder OK, but the popup appears every time!

Sorry if i'm being stupid but I haven't done much JavaScript...
Cheers for any advice here.

function openWindow(winfile)
function popUp()
expireDate=new Date
document.cookie="beenHere="+beenHere+";expires=" +expireDate.toGMTString()



Mrs G
08-02-2002, 08:10 PM
I have attached a text file with a script for "popup once"

Might be what you're after, works on my site.

08-03-2002, 01:06 AM
Thanks Mrs G,

Your reply was appreciated. Downloaded the attachment 5 times (Doh!) before I worked out how to save the source on my Hdd.

The code seems Mega more complex than the original, but then that is maybe the problem here with so many platforms and O/S out there... I will analyse and try it out tomorrow.

As a footnote, the original script was given to me by a college tutor as part of an advanced web programming course - A friend and all but I still await a solution, cause it don't work as given!

Blessu og tak fra Island

08-03-2002, 05:32 AM
this is what I use....

function PopUp(PopUpUrl){
var ScreenWidth=window.screen.width;
var ScreenHeight=window.screen.height;
var movefromedge=0;
WinPop=window.open(PopUpUrl,"","width=400,height=300,toolbar=0,location=0,directories=0,status=0,scrollbars=0,menubar=0,resizable=0, left="+placementx+",top="+placementy+",screenX="+placementx+",screenY="+placementy+",");
function CheckCookie(PopName) {
var ReturnVal = "";
var PopV = PopName + "=";
if (document.cookie.length > 0) {
OffSet = document.cookie.indexOf(PopV);
if (OffSet != -1) {
OffSet += PopV.length;
End = document.cookie.indexOf(";", OffSet);
if (End == -1)
End = document.cookie.length;
ReturnVal=unescape(document.cookie.substring(OffSet, End));
return ReturnVal;
function LOadIt(){
if (CheckCookie("Popped")==""){
<body onload="LOadIt()">

this code can be generated on here: http://www10.brinkster.com/A1ien51/scripts/PopUpWinGenV3.htm

Mrs G
08-03-2002, 10:14 AM
I tried the script you posted above and nothing happens.

This is because there are no cookie functions

08-03-2002, 06:34 PM
Spooky if you want to use session only cookies as indicated by your topic, then you don't need to expire the cookie. It will last until the end of the session. The following should work just fine provided there are no other cookies from that domain:

function popUp(){
var beenHere="hello"

If there are other cookies then document.cookie obviously won't be empty and you'll need to check for that specific cookie instead. Post back if you still have problems.

08-03-2002, 09:05 PM
With other cookies:

<script type="text/javascript" language="JavaScript">
getCookie = document.cookie;
function getTag(name) {
index = getCookie.indexOf(name + "=");
if (index == -1) return null;
startVal = getCookie.indexOf("=", index) + 1;
finishVal = getCookie.indexOf(";", startVal);
if (finishVal == -1) finishVal = getCookie.length;
return unescape(getCookie.substring(startVal, finishVal)); }
if (!getTag("firstVisit")) {

document.cookie = "firstVisit=true";


08-06-2002, 12:01 AM
Hi all,

My thanks also to Alien51, boywonder and Pooh for their suggestions. They will all be tried for an effective solution on my little community (charity) site.

So far Mrs G's solution works out (but I'm working on the timer as it's not quite right for me...) Just a shame the original short script don't work!

Cheers from JavaScript newbie! :) :o :thumbsup:

Mr J
08-17-2002, 04:01 PM
Explain your timer requirements

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum