/    Sign up×
Community /Pin to ProfileBookmark

Why doesn’t the popup work?

I am using this script so a popup comes out only once:

[code=php]
<html xmlns:v=”urn:schemas-microsoft-com:vml” xmlns:o=”urn:schemas-microsoft-com:office:office” xmlns=”http://www.w3.org/TR/REC-html40″>

<head>

<meta http-equiv=”Content-Language” content=”en-us”>
<meta name=”GENERATOR” content=”Microsoft FrontPage 5.0″>
<meta name=”ProgId” content=”FrontPage.Editor.Document”>
<meta http-equiv=”Content-Type” content=”text/html; charset=windows-1252″>
<link rel=”File-List” href=”Index2_files/filelist.xml”>
<title>Welcome to Dragon’s Lair</title>
<!–[if !mso]>
<style>
v:* { behavior: url(#default#VML) }
o:* { behavior: url(#default#VML) }
.shape { behavior: url(#default#VML) }
</style>
<![endif]–>

<SCRIPT LANGUAGE=”JavaScript”>
<!– Begin
var expDays = 1; // number of days the cookie should last
var page = “popup4.htm”;
var windowprops = “width=300,height=200,location=no,toolbar=no,menubar=no,scrollbars=yes,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);
}
}
// End –>
</script>

<?xml version=”1.0″ encoding=”iso-8859-1″?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN”
“http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>

<!–[if gte mso 9]>
<xml><o:shapedefaults v:ext=”edit” spidmax=”1027″/>
</xml><![endif]–>

</head>
<body onLoad=”checkCount()” bgcolor=”#000000″ text=”#FFFFFF” link=”#FFFF00″ vlink=”#FF9900″>

[/code]

Why doesn’t the popup work?

Thanx guys

to post a comment
JavaScript

15 Comments(s)

Copy linkTweet thisAlerts:
@PittimannJan 20.2004 — Hi!

I don't have any idea about your very first tag's sense but that shouldn't bother you ?

There is a line break in the line:

var windowprops ="..."

After removing that, the popup popped up...

Cheers - Pit
Copy linkTweet thisAlerts:
@aommasterauthorJan 20.2004 — what should it look like after editting?

Thanx
Copy linkTweet thisAlerts:
@PittimannJan 20.2004 — Hi!

Put all this in ONE line:

var windowprops = " width=300,height=200,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes";

The line break to be deleted is behind "menuba".

Cheers - Pit
Copy linkTweet thisAlerts:
@aommasterauthorJan 20.2004 — This is the full line:
[code=php]
var windowprops = "width=300,height=200,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes";
[/code]


it still doesn't work!
Copy linkTweet thisAlerts:
@aommasterauthorJan 20.2004 — Hi, i reinserted the script (it got messed up as i was editting!)

this is what the line you told me looks like:
[code=php]
var windowprops = "width=300,height=200,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes";
[/code]


It yet doesn't work, any other ideas?
Copy linkTweet thisAlerts:
@PittimannJan 20.2004 — Hi!

To me it seemed like you intended the popup only to appear, if the cookie has not yet been set. Look at your function:
[code=php]
function checkCount() {
var count = GetCookie('count');
if (count == null) {
count=1;
SetCookie('count', count, exp);
window.open(page, "", windowprops);
}
else { //cookie already set=> no popup
count++;
SetCookie('count', count, exp);
}
}
[/code]

You can change it to:

function checkCount() {

var count = GetCookie('count');

if (count == null) {

count=1;

SetCookie('count', count, exp);

window.open(page, "", windowprops);

}

else {

count++;

alert(count);

SetCookie('count', count, exp);

window.open(page, "", windowprops);

}

}

I inserted the alert as well to "display the cookie"...

Cheers - Pit
Copy linkTweet thisAlerts:
@aommasterauthorJan 20.2004 — well, i wanted the popup to ONLY appear if the cookie is not present. So in other words, the first visit of the site, will cause the popup to appear, and will put a cookie. This means that the second time the visitor enters the site, he will not be bothered by the popup.

I did not really understand the post u replied to me, about displaying the cookie


thanx
Copy linkTweet thisAlerts:
@PittimannJan 20.2004 — Hi!

Why do you wonder then if the popup doesn't show up?

Your popup didn't show up in the beginning because of the line break I mentioned BUT THE COOKIE WAS SET.

Now you have that cookie on your machine; conclusion: no popup.

That dosn't mean that is does not work.

It works. Remove the cookie, check again and you will see, the popup will come...

You could as well use my last code to display the number, then reinsert your own code and replace:

if (count == null) { with if (count == theNumberYouGotInTheAlert) {

then the popup should appear (once, because next time the var count will be two; it would appear a second time, when count again reaches the number from the alert) ...

Cheers - Pit
Copy linkTweet thisAlerts:
@aommasterauthorJan 20.2004 — oh ok! so the script is working! And what would the cookie be called, can i change the name of the cookie?
Copy linkTweet thisAlerts:
@PittimannJan 20.2004 — Hi!

You are able to set and get cookies without knowing the cookie's name? ? ? ?

You are passing its' name as an argument to the get and set function!

Here the contents of your cookie on my machine:

count

2

~~local~~/C:myPath

1088

1088610688

29614072

394037184

29613871

*

Cheers - Pit
Copy linkTweet thisAlerts:
@aommasterauthorJan 20.2004 — Sorry for bothering u pittiman ? Just have a look at this code, fresh from the HTML!
[code=php]
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var expDays = 1;
var page = "popup4.htm";
var windowprops = "width=350,height=300,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);
}
}
// End -->
</script>
[/code]


This is all in the head

And this is in the body:
[code=php]
<body onLoad="checkCount()" bgcolor="#000000" text="#FFFFFF" link="#FFFF00" vlink="#FF9900">
[/code]


I have cleared the cache and the cookies from my computer, but it still doesn't work. I also checked the line breaks that you were talking about, and i fixed it. What is wrong with the code now ? ? ?
Copy linkTweet thisAlerts:
@PittimannJan 20.2004 — Hi!

Sorry - was out for work!

The code works; except that the same linebreak I mentioned before still exists. That will give a js error and due to that the popup cannot appear.

I don't know why, often when I post code, there will be linebreaks in the text, which I hadn't put there. The same happens with other peoples' posts. In such a case - if you copy a code from here and paste it into your editor - you also paste the linebreak(s). You will then have to get rid of it...

Cheers - Pit
Copy linkTweet thisAlerts:
@aommasterauthorJan 20.2004 — sorry pittiman,

i can't see the line break anywhere! can u just highlight the linebreak's area for me?

Thanx pittiman
Copy linkTweet thisAlerts:
@PittimannJan 20.2004 — Hi!

Concerning the linebreaks: I think, you also are a victim of the software here. Very likely, you don't have the linebreak on your machine, but here it appears (exactly where I said in a previous post).

So I continued complaining about your linebreaks and at home you don't have them :rolleyes:...

As far as the popup is concerned (and the cookie): it works ok in NS 4.7, MSIE 6 and Mozilla - don't know, why you still have a prob ?

Cheers - Pit
Copy linkTweet thisAlerts:
@aommasterauthorJan 21.2004 — Ok .Thanx alot Pittiman for your help. Sorry to bother u

Have a good day!
×

Success!

Help @aommaster 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.19,
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,
)...