Question

Modify JS cookie script to close CSS layer

Asked by: lherrou

I'm using a standard JS popup-once cookie script, from www.yaldex.com. However, it is designed to popup a new window one time only. Instead, I am popping up a CSS layer. I need to modify the script to trigger the "hide" function if the visitor has been to the site before. I am not a JS programmer, I am sort of cobbling together some different things, and trying to make them work.

Here's the relevant sections of code:

- - - Checks Cookie and runs WindowOpen if haven't been there before - - -
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);
   }
}

- - - current code to close CSS layer by clicking on Image - - -
<td style="cursor:hand"><a href="#" onClick="hidebox();return false"><img src="close.gif" width="16px" height="14px" border=0></a></td>

- - - code of hidebox() function - - -
function hidebox(){
crossobj=ns6? document.getElementById("showimage") : document.all.showimage
if (ie4||ns6)
crossobj.style.visibility="hidden"
else if (ns4)
document.showimage.visibility="hide"
}

- - - - - -
Seems like if I could replace the "window.open(page, "", windowprops);" with something that triggers the hidebox() function, I would be set.

Thanks!

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-07-27 at 11:57:20ID21934447
Tags

modify

,

layer

,

css

,

cookie

,

close

Topic

JavaScript

Participating Experts
2
Points
500
Comments
20

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Susbtitute js-menu with css - is it possible
    Hello, i have a shopping site, working with 4 frames. One frame for content, one frame at the left side of the content area using a slide-menu working with css, one top frame for selecting product categories with a js-rollover-menu and one bottom frame for user logins. The t...
  2. Caching .js and .css file
    I got a JSP page that includes .js and .css file. what I want to do is, I want to cache both .js and .css file in local computer but not the JSP file. How should I do that? How do I test whether it work or not? This is because I don't want to do burden the server traffic fl...
  3. CSS/JS/CF toggle CSS based on query output
    I am posting this question under javascript because it relates more closely with JS/CSS than Coldfusion, however Coldfusion is the server script language I'm using and the result is based upon what is outputed from a query. basically want to add a bit more functionality to t...
  4. CSS/JS - Toggle Fieldset Border
    I am lookign for a way - within JS/CSS to toggle the border from 0px to 1 px - with the click of a checkbox, for a fieldset - is this possible and if so how?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: cLFlaVAPosted on 2006-07-27 at 11:59:19ID: 17195575

replace this:

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


with this:

hidebox();

 

by: lherrouPosted on 2006-07-27 at 12:12:53ID: 17195687

I tried that, but it doesn't hide the box. Box still closes by clicking on the image, and the cookie shows up in my browser's cookie list, but...

 

by: cLFlaVAPosted on 2006-07-27 at 12:25:08ID: 17195785

where are you setting the value of ns6 and ns4 and ie4?

 

by: lherrouPosted on 2006-07-27 at 12:29:53ID: 17195829

I'm not sure what you're asking?

 

by: cLFlaVAPosted on 2006-07-27 at 12:32:41ID: 17195857

in your hidebox function, you reference those three variables.  i am wondering where their values are set.  if they're never set in your code, then the code won't run.

 

by: lherrouPosted on 2006-07-27 at 12:44:11ID: 17195940

Except that the hidebox function works for the onclick and also if the form is submitted, so it's not a problem with the hidebox function.

 

by: cLFlaVAPosted on 2006-07-27 at 12:47:20ID: 17195964

where is your hidebox function declared?
where is your checkCount function declared?

 

by: DireOrbAntPosted on 2006-07-27 at 13:15:57ID: 17196181

Does the site use IFRAMEs or FRAMEs? I so, showimage might not be in the same context.
Also, replace:
window.open(page, "", windowprops);
By:
alert('count = 1')

Do you see an alert? If not, the cookie code never gets there.

 

by: lherrouPosted on 2006-07-27 at 13:34:33ID: 17196337

No, the site does not use any Frames or IFrames. The Alert popup box pops up the first load, and does not on subsequent loads (until I delete the cookie, etc.)

Hidebox is declared in the page <head> section, checkCount() in the body.

 

by: cLFlaVAPosted on 2006-07-27 at 13:36:40ID: 17196359

can you post your entire code or give us a link>?  there is probably something missing.

 

by: lherrouPosted on 2006-07-27 at 13:51:46ID: 17196466

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

<meta name="Keywords" content="REMOVED" />

<meta name="Description" content="REMOVED." />

<title>REMOVED</title>
<script type="text/javascript">

/******************************************
* Popup Box- By Jim Silver @ jimsilver47@yahoo.com
* Visit http://www.dynamicdrive.com/ for full source code
* This notice must stay intact for use
******************************************/

var ns4=document.layers
var ie4=document.all
var ns6=document.getElementById&&!document.all

//drag drop function for NS 4////
/////////////////////////////////

var dragswitch=0
var nsx
var nsy
var nstemp

function drag_dropns(name){
if (!ns4)
return
temp=eval(name)
temp.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)
temp.onmousedown=gons
temp.onmousemove=dragns
temp.onmouseup=stopns
}

function gons(e){
temp.captureEvents(Event.MOUSEMOVE)
nsx=e.x
nsy=e.y
}
function dragns(e){
if (dragswitch==1){
temp.moveBy(e.x-nsx,e.y-nsy)
return false
}
}

function stopns(){
temp.releaseEvents(Event.MOUSEMOVE)
}

//drag drop function for ie4+ and NS6////
/////////////////////////////////


function drag_drop(e){
if (ie4&&dragapproved){
crossobj.style.left=tempx+event.clientX-offsetx
crossobj.style.top=tempy+event.clientY-offsety
return false
}
else if (ns6&&dragapproved){
crossobj.style.left=tempx+e.clientX-offsetx+"px"
crossobj.style.top=tempy+e.clientY-offsety+"px"
return false
}
}

function initializedrag(e){
crossobj=ns6? document.getElementById("showimage") : document.all.showimage
var firedobj=ns6? e.target : event.srcElement
var topelement=ns6? "html" : document.compatMode && document.compatMode!="BackCompat"? "documentElement" : "body"
while (firedobj.tagName!=topelement.toUpperCase() && firedobj.id!="dragbar"){
firedobj=ns6? firedobj.parentNode : firedobj.parentElement
}

if (firedobj.id=="dragbar"){
offsetx=ie4? event.clientX : e.clientX
offsety=ie4? event.clientY : e.clientY

tempx=parseInt(crossobj.style.left)
tempy=parseInt(crossobj.style.top)

dragapproved=true
document.onmousemove=drag_drop
}
}
document.onmouseup=new Function("dragapproved=false")

////drag drop functions end here//////

function hidebox(){
crossobj=ns6? document.getElementById("showimage") : document.all.showimage
if (ie4||ns6)
crossobj.style.visibility="hidden"
else if (ns4)
document.showimage.visibility="hide"
}

</script>
</head>
<body>
  <script  language="javascript"  type="text/javascript">
/* Visit http://www.yaldex.com/ for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
var expDays = 1; // number of days the cookie should last

var page = "http://www.yaldex.com";
var windowprops = "width=300,height=200,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);

alert('count = 1')

}
else {
count++;
SetCookie('count', count, exp);
   }
}
window.onload=checkCount;
//  End -->
</script>


// BUNCH OF HTML


<!-- Begin popup for subscription -->
<div id="showimage" style="position:absolute;width:250px;left:250px;top:280px">

<table border="0" width="250" bgcolor="#478C9B" cellspacing="0" cellpadding="2">
  <tr>
    <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0"
    height="36px">
      <tr>
        <td id="dragbar" style="cursor:hand; cursor:pointer" width="100%" onMousedown="initializedrag(event)"><ilayer width="100%" onSelectStart="return false"><layer width="100%" onMouseover="dragswitch=1;if (ns4) drag_dropns(showimage)" onMouseout="dragswitch=0"><font style="color: #fff;font-size: small;font-family: "Verdana", "Arial", "Helvetica", sans-serif;"><strong>Subscribe to our newsletter</strong></font></layer></ilayer></td>
        <td style="cursor:hand"><a href="#" onClick="hidebox();return false"><img src="close.gif" width="16px"
        height="14px" border=0></a></td>
      </tr>
      <tr>
        <td width="100%" bgcolor="#FFFFFF" style="padding:4px" colspan="2">

<!-- PUT YOUR CONTENT BETWEEN HERE -->
<form action="http://www.somewebsite.com/motmail/box.php" method="post" target="mywin" onsubmit="window.open('','mywin','resizable,height=300,width=500'); hidebox(); return false;">
 <table width="212"
border="0" cellspacing="0" cellpadding="0"> <tr> <td width="75"><div
align="right">E-mail</div></td> <td><div align="right"> <input
name="email" type="text" id="email" value="" size="16"> </div></td> </tr>
<tr> <td width="75"><div align="right">Name</div></td> <td><div
align="right"> <input name="name" type="text" id="name" value=""
size="16"> </div></td> </tr>
    <tr>
<td width="75"><div align="right"> </div></td>
<td> <div align="left">    
<input name="funcml" type="radio" value="add" checked>Subscribe</div></td>
</tr> <tr> <td width="75"><div align="right"> </div></td> <td> <div
align="left">     <input name="funcml" type="radio"
value="unsub2">Unsubscribe</div></td> </tr> <tr> <td width="75"><div
align="right"> <input name="p" type="hidden" id="p" value="21">
  <input type="hidden" name="nlbox[1]" value="53">
  </div></td>
<td> <div align="right">
<br>
<input type="submit" name="Submit" value="Submit">
</div></td>
</tr>
</table>
</form>

<!-- END YOUR CONTENT HERE -->

</td>
      </tr>
    </table>
    </td>
  </tr>
</table>
</div>

</body>
</html>

 

by: lherrouPosted on 2006-07-27 at 13:53:34ID: 17196479

That's the version where I inserted the Alert box....

 

by: cLFlaVAPosted on 2006-07-27 at 13:58:23ID: 17196515

haha...

what's this "hide" css?  it's "hidden":

function hidebox(){
    crossobj=ns6? document.getElementById("showimage") : document.all.showimage
    if (ie4||ns6)
        crossobj.style.visibility="hidden"
    else if (ns4)
        document.showimage.visibility="hidden"
}

 

by: cLFlaVAPosted on 2006-07-27 at 13:58:53ID: 17196520

we should have noticed that MUUUUUUUCH earlier!

 

by: lherrouPosted on 2006-07-27 at 14:00:38ID: 17196536

Did you load into a page and view in a browser? You'll see that there's a form that pops up. If you click to submit the form (calling hidebox()), or click in the top right corner of the form (also calling hidebox()), the form goes away. I want it to go away if they have been to the site before as well.

In other words, it's not hidden until hidebox() is called...

 

by: DireOrbAntPosted on 2006-07-27 at 17:16:34ID: 17197582

I got the alert the first time and not the other times. So I guess it's working.

Oh, I see, you inversed your rules... This is how checkcount should be:
function checkCount() {
  var count = GetCookie('count');
  if (count == null) {
    count=1;
    SetCookie('count', count, exp);
  } else {
    count++;
    SetCookie('count', count, exp);
    hidebox();
  }
}

 

by: lherrouPosted on 2006-07-27 at 17:28:33ID: 17197611

DireOrbAnt = Thanks!

I'm splitting points.

 

by: cLFlaVAPosted on 2006-07-27 at 17:41:21ID: 17197654

interesting choice.  does it still work with the "hide" css?

 

by: lherrouPosted on 2006-07-27 at 19:03:19ID: 17197941

Yes, it works exactly as I needed it to.

 

by: DireOrbAntPosted on 2006-07-27 at 19:33:44ID: 17198057

That block was for netscape 4 only. In the good old days N4 supported object.visibility = 'hide' or 'show'.
Who's the full package now cLFlaVA ?

Just kidding ;)

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...