Solved

Javascript cookie deletion, IE vs Netscape

Posted on 2000-03-28
5
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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

739 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