473,395 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Have a Javascript that keeps a cookie on a popup

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
5 1966
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ken | last post by:
I am new to PHP. But this seems like a terrific language. I have been using JavaScript up to now but it looks like I will be changing to PHP. Seems to have more potential. I am confused about...
2
by: Michael | last post by:
I am reading and setting a cookie using JavaScript in the BODY onload and onunload events respectively. This works fine. However when I use ASP to set the cookie under some condition where I...
1
by: Ben Wan | last post by:
I got 2 error from the following code below... 1. I couldn't load up the picture since the picture is at (C:\company\image\largePic.jpg) 2. I got a page error in my 'index.html' when calling...
12
by: chrism | last post by:
Hello, I have a pop-up window that I would like to appear in front of the browser home page when a user opens IE. Problem is, I'd like it to never appear again if the user navigates back to the...
3
by: M Wells | last post by:
Hi All, Just wondering how you go about changing the value of a session cookie via javascript? I have a PHP page that sets a session cookie when it first loads. I'd like to be able to change...
0
by: malcolm | last post by:
How do I get a web-browser loaded with on-the-fly content and a JavaScript onclick popup function to work? I've embedded an axWebBrowser in my (vb.net) application. The browser starts with...
3
by: John Bokma | last post by:
I have two windows in a frame. I want to be able that each can open a pop up window and that the handle to that window can be stored somewhere, so that each can talk to the pop up. is it...
6
by: nate | last post by:
Hello, Does anyone know where I can find an ASP server side script written in JavaScript to parse text fields from a form method='POST' using enctype='multipart/form-data'? I'd also like it to...
7
by: Steph | last post by:
Bonjour, Je souhaite lancer une redirection vers un fichier php via SRC= dans une condition if (voir ci-dessous en bas du script) mais la redirection ne fonctionne pas. Par contre la condition...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.