473,725 Members | 2,232 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>Softwa re-In-A-Box.com</title>
<meta description="A computer software company that sells computer games
and other computer software to
consumers">
<meta keywords="compu ter software, computer games, computer stuff>
<link rel="stylesheet " href="styleshee t.css" type="text/css">
<script LANGUAGE="Javas cript">
<!-- Hide javascript from older browsers --
function PopUp(theURL,wi nName,features)
{window.open(th eURL,winName,fe atures);}
// 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="JavaS cript" type="text/JavaScript">
<!--
function MM_jumpMenu(tar g,selObj,restor e){ //v3.0
eval(targ+".loc ation='"+selObj .options[selObj.selected Index].value+"'");
if (restore) selObj.selected Index=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.cooki e.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.argum ents;
var argc = SetCookie.argum ents.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.toGMTSt ring())) +
((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('coun t')
if(count == null) {
SetCookie('coun t','1')
return 1
}
else {
var newcount = parseInt(count) + 1;
DeleteCookie('c ount')
SetCookie('coun t',newcount,exp )
return count
}
}
function getCookieVal(of fset) {
var endstr = document.cookie .indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie .length;
return unescape(docume nt.cookie.subst ring(offset, endstr));
}

function checkCount() {
var count = GetCookie('coun t');
if (count == null) {
count=1;
SetCookie('coun t', count, exp);

window.open(pag e, "", windowprops);

}
else {
count++;
SetCookie('coun t', count, exp);
}
}
/ End -->
</script>
</head>

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

Jul 23 '05 #1
5 1988
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="JavaS cript" >

var expDays = 1;
var page = "Users/walshclan/Desktop/6384/html/popup.html";
var windowprops =
"width=200,heig ht=200,location =no,toolbar=no, menubar=no,scro llbars=no,resiz able=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.cooki e.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.argum ents;
var argc = SetCookie.argum ents.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.toGMTSt ring())) +
((!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('coun t');
alert("hello world");
if(!count) {
SetCookie('coun t','1');
return 1;
}
else {
var newcount = parseInt(count) + 1;
DeleteCookie('c ount');
SetCookie('coun t',newcount,exp );
return count;
}
}
function getCookieVal(of fset) {
var endstr = document.cookie .indexOf (";", offset);
if (endstr == -1)
{endstr = document.cookie .length;}
return unescape(docume nt.cookie.subst ring(offset, endstr));
}

function checkCount() {
var count = GetCookie('coun t');
alert("hello world");
if (!count) {
count=1;
SetCookie('coun t', count, exp);

window.open(pag e, "", windowprops);

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

function test () {
alert("hello world");
}
</script>
</head>
<body onload="checkCo unt()">
</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>JavaScri pt Test</title>
<script type="text/javascript" >
.....

* <http://validator.w3.or g/>

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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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
1971
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 using data in a JavaScript cookie in a PHP file. The JavaScript Cookie document.cookie = "order=" + escape("website = " + website + "*" + "sale = " + sale + "*" + "name = " + name + "*" + "addr1 = " + addr1 + "*" + "addr2 =
2
5580
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 want to override the last value set in the onunload event, it has no effect. The next onload still has the old value. Any ideas? The following code simulates the problem I experience. --------------------------------------------------
1
6506
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 popup(x,x,x) for the 2nd time. The code are as followed. Can anyone help please? Thank you very much~~ Ben
12
18010
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 home page during their time using the browser. However, if the user closes the browser, then reopens, the pop-up should appear again. (you may have guessed that this will be used for public access pc's.) I want to try as best I can to catch...
3
5975
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 the value of that session cookie in response to a button click in a form, without resubmitting the page. For some reason, the following doesn't seem to work:
0
1587
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 about:blank, and then I set AxWebBrowser1.Document.Body.innerHTML to the desired HTML. The HTML contains a link (which works fine) and a Javascript command to put up a popup window. (The popup will show more on-the-fly content.) The HTML and...
3
3543
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 possible that window 1 in a frameset calls a function in window 2, ie. something like: window 1: ....
6
6104
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 parse the filename. <form name='form1' method='POST' enctype='multipart/form-data' action='sub.asp'> <input type='text' name='title1' value='value1'> <input type='file' name='file1'>
7
2115
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 est bien validée car le cookie (crée précédemment) est bien effacé par SetCookie. Pourriez-vous me dire ce qui ne va pas ? Merci d'avance Steph
0
8888
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9176
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9113
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8097
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.