Solved

Javascript cookie deletion, IE vs Netscape

Posted on 2000-03-28
5
267 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

839 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