Copy link to clipboard
Copied
Hello, everyone.
Copy link to clipboard
Copied
I would think that J2EE sessions are the only types of sessions that know when the browser is closed, so you would have to use J2EE session vars, and then in your onSessionEnd, go through the process of terminating the file.
Note that in your onSessionEnd, you cannot reference, SESSION scope, since it doesn't exist anymore. You'll have to reference the session object argument that you can pass in as an argument.
Copy link to clipboard
Copied
No J2EE sessions DO NOT know when the browser is closed.
All that happens with J2EE sessions is that the cookie the browser was using is thrown away when the browser is closed. Thus if a new browser is opened to this site, a new cookie will be generated with a new session. But the old session data is still there until the session time out period expires. Because browsers don't go around to all the web sites you may have visited since starting up saying something like "I'm closing now".
P.S. Regular, old fashioned, CFID and CFTOKEN cookies can also be made to be memory cookies that are thrown away when the browser closes like the JSESSIONID cookie used with J2EE sessions. It's just that the JSESSIONID is a memory cookie by default.
Copy link to clipboard
Copied
We use a different approach. We have a scheduled job that looks in designated directories and deletes anything more than 30 days old.
Copy link to clipboard
Copied
It depends on how time sensitive you want this to be.
The easy way would be to put the code to clean up these directories in the OnSessionEnd() event of an Applicaiton.cfc. This event will fire when the session ends after the time out period expires (20 minutes by default).
If you want something to actually happen when the popup is closed. Since it is a JavaScript popup, there are JavaScript events fired when it closes. You could write code that executes when this event happens. That code could easily use AJAX or some other method to make a request to a 'cleanup.cfm' page which wuld do the desired task.
If I where to do number two, I would still do number one to cover all the cases where the something happens that does not fire off the event, like the user closes the entire browser or have their browser or computer crash, etc.
And if you are doing number one, you should ask yourself if there is enough benifit to number two to bother with all the extra work to create and maintain another section of code to have this happen twenty minutes sooner then it is going to happen anyway.
Copy link to clipboard
Copied
Session variables have been disabled, so I don't know if #1 would work.
#2 is more along what I'm looking for, but the few references I've found for file manipulation using JavaScript haven't worked. I've tried the "onBeforeUnload", but even if it did work, it would delete the file as soon as the user clicked Submit.
^_^
Copy link to clipboard
Copied
WolfShade wrote:
I've found for file manipulation using JavaScript haven't worked
You don't want to manipulate the file with JavaScript. The file(s) aren't anywhere where JavaScript can manipulate them. JavaScript is going to run on the client, the files are on the server. They do NOT share a file system.
What you want to do is manipulate the REQUEST. You use JavaScript to make a request to the server. This request is for a ColdFusion template that will delete the desired files. This can be accomplished pretty simple with either AJAX or small inline frames that make a request to the server.
From the server side, it does not know or care that the request is from a JavaScript function on the client rather than the more common anchor click, form submit or URL input. It just does what it has been coded to do when it is requested.
But since the request is from a JavaScript function, the user interface doesn't have to change in any way when doing this request.
But YOU really need to consider what to do when all that fancy JavaScript DOES NOT WORK. This can happen for many reasons. Users have JavaScript disabled. Users close the browser in a manner that does not trigger the JavaScript event. Users just turn of the system or it crashes.
If you don't have sessions enabled, then a scheduled task that runs on a certain period would probably be the next best option.
Copy link to clipboard
Copied
You can't really know when the browser is closed. You only know when the browser made its last request. You can use onSessionEnd to do this sort of cleanup, as that will run when the session has timed out (by default, 20 minutes after the last request from the browser).
Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
http://training.figleaf.com/
Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on
GSA Schedule, and provides the highest caliber vendor-authorized
instruction at our training centers, online, or onsite.
Read this before you post:
http://forums.adobe.com/thread/607238
Copy link to clipboard
Copied
Why don't you have the file uploaded to the temporary directory on the server ( i.e. - GetTempDirectory() )? It'll eventually be removed on its own.
If you're wanting to go with the JavaScript option, you could use a variable in your JavaScript to determine whether or not to remove the file when the window is closed.
Example:
<script language="text/javascript">
doDeleteOnClose = true;
// Function called before closing the window
function deleteFileOnClose() {
if (doDeleteOnClose) {
// Code to delete the file
}
}
// Function called before submission of the form
function doBeforeSubmit() {
doDeleteOnClose = false;
return true;
}
</script>
<form onSubmit="javascript: doBeforeSubmit();">
<input type="submit" name="submit" value="Submit" />
</form>
--
Daniel Jeffery
Vivio Technologies
http://www.viviotech.net/
http://www.linkedin.com/in/jeffda