Solved

Javascript cookie deletion, IE vs Netscape

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

746 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

9 Experts available now in Live!

Get 1:1 Help Now