Jump to content

How to kill a session when window is closed


joecool2005

Recommended Posts

Try this example html code<a href="java script:void(0)" onclick="window.open('https://secure.drtax.ca/ufileshop/2006/storespec.asp')">2006</a><a href="java script:void(0)" onclick="window.open('https://secure.drtax.ca/ufileshop/2005/storespec.asp?taxyear=2005')">2005</a>Click on 2006 first, a child window will open and you will see a line written "UFile 2006 for Windows". Then close the child window and click on 2005. You are suppose to see a line written "UFile 2005 for Windows". That's not the case. It showed "UFile 2006 for Windows" because of the session variable Session("year") is still alived. Both link you use the same global.asaIf you close all the windows et redo the same exercice this time by clicking on 2005 first you will see "UFile 2005 for Windows" for both link.Thx for your help

Link to comment
Share on other sites

When one window opens another one, the same session is active for both windows. Closing the window that a parent opened does not end the session for the parent. You will need to rethink how you are using the session on these pages. It sounds like you don't even need to store the year in the session if you have it in the URL.

Link to comment
Share on other sites

Here is how you do it in ColdFusion:

<!--- clearing session when browser closes ---><cfif ISDEFINED("cookie.CFID") and ISDEFINED("cookie.CFTOKEN")>	<cfset localCFID = Cookie.CFID>	<cfset localCFTOKEN = Cookie.CFTOKEN>	<cfcookie name="CFID" value="#localCFID#">	<cfcookie name="CFTOKEN" value="#localCFTOKEN#"></cfif>

Technically, this clears the session when a new window is opened (not when the current one is closed) when no other window exists.Essentially, I am looking to see if the connection to the server that was just created matches the session that is registered with the current browser. If not, then I reset the session - if so, then I do nothing as the current session is valid.I do not know enough about ASP to give the equivalent solution, but I thought the logic might help.So, don't think about ending the session when the browser closes - there is no fail save way to determine that. What is more feasible is to check when a new application session has been created or requested - then you can scrap any of the old ones associated with that current browser.This, of course, is only an issue when dealing with persistent cookies or sessions. If, like justsomeguy states you are not using persistent cookies or sessions, then when all browser windows are close, the session will terminate.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...