By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,920 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,920 IT Pros & Developers. It's quick & easy.

Have a Javascript that keeps a cookie on a popup

P: n/a
Hi:

I gleaned a javascript off of the web:

http://www.hypergurl.com/popup.html

that sets a cookie everytime someone visits your site. If it is the
first visit in x number of days then a popup will appear. It would be
great for my application but I can't get it to work. Here is my code:

http://www.software-in-a-box.com/sho.../template.html

Here is where my site is displayed (and the popup should show up):

http://www.software-in-a-box.com/shop

Here is a snippet of my code. I tried putting open.window's in my code
in the checkcount and getcookie functions and no window was opened. Is
there an easier thing to debug with. I use safari and I hear it has no
debugger...sux. I have no idea what was going on. I tried netscape still
no windows.

Thanks for any help you can provide.

Connie

<html>
<head>
<title>Software-In-A-Box.com</title>
<meta description="A computer software company that sells computer games
and other computer software to
consumers">
<meta keywords="computer software, computer games, computer stuff>
<link rel="stylesheet" href="stylesheet.css" type="text/css">
<script LANGUAGE="Javascript">
<!-- Hide javascript from older browsers --
function PopUp(theURL,winName,features)
{window.open(theURL,winName,features);}
// end hide -->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
..txt1 {
font: 10px Tahoma;
color: #5A5A5A;
}
..txt2 {
font: 11px Tahoma;
color: #5A5A5A;
}
..txt3 {
font: 11px Tahoma;
color: #5A5A5A;
}
body,td,th {
font-size: 10px;
}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
<!-- Begin
var expDays = 2; / number of days the cookie should last
var page =
"http://www.software-in-a-box.com/shop/skin_default/popup.html"; /URL to
the pop-up
var windowprops = ""; / variables
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>
</head>

<body style="padding:0;margin:0 " onLoad="checkCount()" >
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>

Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Connie Walsh wrote:
... I use safari and I hear it has no
debugger...


Safari has excellent debug support, read the FAQ # 4.43

http://jibbering.com/faq/
Jul 23 '05 #2

P: n/a
Well after some digging I found jslint. A javascript verifier.
Apparently there were a lot of problems with the code. I have posted the
working copy here: (take out the extra Hello world lines)

Connie
<html>
<head>

<script LANGUAGE="JavaScript" >

var expDays = 1;
var page = "Users/walshclan/Desktop/6384/html/popup.html";
var windowprops =
"width=200,height=200,location=no,toolbar=no,menub ar=no,scrollbars=no,resizable=no";

function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
alert("hello world");
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 ) {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) ? "" : ("; expires=" + expires.toGMTString())) +
((!path) ? "" : ("; path=" + path)) +
((!domain) ? "" : ("; domain=" + domain)) +
((secure) ? "; secure" : "");
}
function DeleteCookie (name) {

var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
alert("hello world");
}
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt(){
var count = GetCookie('count');
alert("hello world");
if(!count) {
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');
alert("hello world");
if (!count) {
count=1;
SetCookie('count', count, exp);

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

}
else {
count++;
SetCookie('count', count, exp);
}
}

function test () {
alert("hello world");
}
</script>
</head>
<body onload="checkCount()">
</body>
</html>

Jul 23 '05 #3

P: n/a
On Wed, 22 Sep 2004 02:15:20 -0400, Connie Walsh wrote:
Well after some digging I found jslint. A javascript verifier.
Apparently there were a lot of problems with the code. I have posted the
working copy here: (take out the extra Hello world lines)


Since you seem to be a person who likes to 'get it just right',
I thought I might suggest that you check the HTML validator* as well.

<!doctype html public "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>JavaScript Test</title>
<script type="text/javascript" >
.....

* <http://validator.w3.org/>

The document also requires something in the <body>
to make the validator very happy.

HTH

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
Jul 23 '05 #4

P: n/a
JRS: In article <2r*************@uni-berlin.de>, dated Wed, 22 Sep 2004
02:15:20, seen in news:comp.lang.javascript, Connie Walsh
<walshclan@_no_spam_primus.ca> posted :
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
Is var exp = new Date(0) not better ?????
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
alert("hello world");
}
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

exp.setDate(exp.getDate() + expDays) // is better; less so if all
// users live in places like
// Hawaii or Uganda

<FAQENTRY>

The FAQ index has nothing general on cookies. Sec 4.4 should be
generalised :
4.4 Why and how are cookies used ?

Cookies are used to maintain information either during ... or for a
longer definable period. Users often do not allow them.

To test whether the present browser accepts cookies, write
a cookie, read it back and check whether it is the same.

For example cookie code, see ...

http://tech.irt.org/articles/js064/index.htm
Additional Notes:
http://www.jibbering.com/faq/faq_notes/cookies.html

if != whether

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #5

P: n/a
In article <2r*************@uni-berlin.de>,
Here is a snippet of my code. I tried putting open.window's in my code
in the checkcount and getcookie functions and no window was opened. Is
there an easier thing to debug with. I use safari


17. Why are my Pop-Up Windows not appearing?

Safari has implemented a pop-up window blocker in order to minimize the
distracting pop-up windows many sites use for advertising. The pop-up
blocker will filter all pop-ups, except those triggered by a user
action, such as a mouse click or a key press. Pop-ups triggered directly
from <script> tags, from the onLoad handler, from the onUnload handler,
or from timers are blocked.

from:
<http://developer.apple.com/internet/safari/safari_faq.html#anchor17>

under preferences > security

You can turn on popups.

Robert
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.