Solved

Javascript cookie deletion, IE vs Netscape

Posted on 2000-03-28
5
258 Views
Last Modified: 2008-03-10
Hi, I created a javascript cookie deletion function, but now it works only under IE, I don't know why.  It's based on an onUnload in the body tag.  When I check my cookies in IE, everything is deleted when I unload that peculiar window, but in Netscape, it doesn't do anything.  Here's the code I use

<HEAD>
<SCRIPT language=javascript>
function clearCookies(){
      var ThreeDays=3*24*60*60*1000;
      var expDate=new Date();
      expDate.setTime (expDate.getTime()-ThreeDays);
      document.cookie="un"+"=asdf; expires="+expDate.toGMTString();
      document.cookie="pwd"+"=asdf; expires="+expDate.toGMTString();
      document.cookie="acc"+"=asdf; expires="+expDate.toGMTString();
      document.cookie="rights"+"=asdf; expires="+expDate.toGMTString();
      document.cookie="SessionID"+"=asdf; expires="+expDate.toGMTString();
}
</SCRIPT>
</HEAD>
<BODY TOPMARGIN=0 LEFTMARGIN=0 onLoad="window.resizeTo(310,135)" onUnload="clearCookies()">

Is there anyone out there that had the same problem?
0
Comment
Question by:Nicolas_St_Amour
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:nettrom
ID: 2664660
what actions do you take to make the unload even run?  if you close the window the unload event may not run correctly because of a race condition.  try putting an alert() inside the clearCookies() function and see if it's actually run.
0
 

Author Comment

by:Nicolas_St_Amour
ID: 2664691
I actually know it runs because it deletes the cookies created by IE, but not those created by Netscape... I just tried it with an alert and for some odd reason, the alert does not pop up in Netscape either in the OnUnload or OnLoad event.

Weird...
0
 
LVL 7

Expert Comment

by:nettrom
ID: 2665304
the point I was trying to make is that whether it runs in IE or not is irrelevant if you use the onunload event and close the Netscape window.  the race condition that occurs, between the closing of the window and the onunload event, may result in the onunload event handler not being run, and therefore the cookies will not be deleted.

strange that the alert doesn't happen in the onload event though.  tried using simply

<body onload="alert('ping!');">

?
0
 

Author Comment

by:Nicolas_St_Amour
ID: 2665442
Yah, I noticed something weird (yet not that weird...)

When I alt-f4 the window that has the onunload event, it runs in IE and not in Netscape, but when I only refresh the same window (onunload occurs), both IE and Netscape run the onunload thingy...

gnah well
0
 
LVL 7

Accepted Solution

by:
nettrom earned 20 total points
ID: 2668545
it's the same behaviour that I've noticed.  it's also mentioned on Netscape's JavaScript bug page, although as frame/frameset unload bug: http://developer.netscape.com/support/bugs/index.html?content=known/javascript.html

it's been mentioned several times in the comp.lang.javascript newsgroup, so if you need references to previous posts let me know, and I'll dug up a frew through Deja News.

and yes, it totally sucks.  when I worked with my little JavaScript remote control I had to create a workaround using the onfocus event in the parent window, instead of simply using onunload.  a very unelegant solution, but unfortunately the only one that worked.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now