Solved

onclose in js

Posted on 2002-04-17
13
879 Views
Last Modified: 2008-03-10
Hello.

I need to delele a cookie when a window is closed. I know there is no onclose event and as far I understood the only possiblitly is to use the onUnload event in the body tag.

Is there any solution to my requeriment working for Netscape and IE?

Thanks in advance
0
Comment
Question by:perevicente
  • 8
  • 3
  • 2
13 Comments
 
LVL 2

Expert Comment

by:serg111
ID: 6947682
You can use session cookie that will be autodeleted after session close without your intervention or set expire time in 10 minutes
0
 

Author Comment

by:perevicente
ID: 6947711
I have two windows opened in the same brower session (one is open with ctrl+N or a link from the first window).

When I close the new one I want to delete the cookie that it sets, but If I close the window without any action the first window remains open and the cookie is still theres (untill all the windows session are closed). That is the reason because I want to delete the cookie when I close the 2nd window.

Does anyone know how to do it correcty for IE and Netscape?

Thanks
0
 
LVL 19

Expert Comment

by:webwoman
ID: 6947748
Why delete it? Why not just reset it in the other window? And I'm not clear why it's a problem...if you don't need it, you don't use it.
0
 

Author Comment

by:perevicente
ID: 6947767
I have a site with a session id depending on the value of a cookie. When I open a link form the first window to open a new site a new cookie is set. If I close this second window the cookie is still there, so if I open again a second window from the first one the cookie exists and I NEED there is no cookie when I open a second window from the first one.
0
 

Author Comment

by:perevicente
ID: 6947800
I have a site with a session id depending on the value of a cookie. When I open a link form the first window to open a new site a new cookie is set. If I close this second window the cookie is still there, so if I open again a second window from the first one the cookie exists and I NEED there is no cookie when I open a second window from the first one.
0
 
LVL 2

Expert Comment

by:serg111
ID: 6947977
You can provide button "Logout" - when user click it - cookies deleted and set timeout for session (or period of inactivity)
0
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.

 
LVL 2

Expert Comment

by:serg111
ID: 6948008
Also if user opens 3 or more windows to your web site and later close one only - should cookies be deleted?
0
 

Author Comment

by:perevicente
ID: 6948027
1er answer: Button logout is not a solution. Most of the users never click it. They simply close the window.

2on : yes

Thanks for your hep but I need to get straight to the point. Is there any way of executing a javascript function just when a window is being close? (working for IE and NN)

Thanks.
0
 

Author Comment

by:perevicente
ID: 6948064
1er answer: Button logout is not a solution. Most of the users never click it. They simply close the window.

2on : yes

Thanks for your hep but I need to get straight to the point. Is there any way of executing a javascript function just when a window is being close? (working for IE and NN)

Thanks.
0
 

Author Comment

by:perevicente
ID: 6948110
1er answer: Button logout is not a solution. Most of the users never click it. They simply close the window.

2on : yes

Thanks for your hep but I need to get straight to the point. Is there any way of executing a javascript function just when a window is being close? (working for IE and NN)

Thanks.
0
 

Author Comment

by:perevicente
ID: 6948160
1er answer: Button logout is not a solution. Most of the users never click it. They simply close the window.

2on : yes

Thanks for your hep but I need to get straight to the point. Is there any way of executing a javascript function just when a window is being close? (working for IE and NN)

Thanks.
0
 

Author Comment

by:perevicente
ID: 6948224
1er answer: Button logout is not a solution. Most of the users never click it. They simply close the window.

2on : yes

Thanks for your hep but I need to get straight to the point. Is there any way of executing a javascript function just when a window is being close? (working for IE and NN)

Thanks.
0
 
LVL 19

Accepted Solution

by:
webwoman earned 80 total points
ID: 6948692
Short answer -- no. You don't know the window is being closed. You only know the page is being unloaded -- maybe. If they close the window without using any buttons you have, even the unload may not be triggered.
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

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

862 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

25 Experts available now in Live!

Get 1:1 Help Now