Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Javascript cookie deletion, IE vs Netscape

Posted on 2000-03-28
5
Medium Priority
?
283 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 80 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
Suggested Courses

971 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