Executing a CF page when the browser is closed or navigates away from a CF page.

Experts,

I need to excute a CF page or file when the user closes the browser or navigates away from a specific CF page.

For example, if the users are closing the browser when they are on finalPage.cfm and I need to excute verifyDetails.cfm page. I also need to get an attribute from finalPage.cfm to verifyDetails.cfm to check my transaction or run verifyDetails.cfm page.

Are there any CF fucntions to do this and is this possible? If so, please let me know how I can do this?

Thanks on Advance.
Tpaul_10Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gdemariaCommented:

Nothing can be done when the browser is closed or someone navigates away from your page.

However, you can use onSessionEnd function in your application.cfc file to run some CF code when the session expires.  The session will expire X minutes (usually 20) after the last activity by the user.

0
Philippe DamervalSenior Analyst ProgrammerCommented:
My first sentiment is to say no, that is the nature of the web, you don't control the client and your templates don't know when the browser was closed at the other end so you can't react to that. However, using Javascript, if a certain data condition arises you can react to it and pop up a dialog which will prevent the user from closing their browser until the dialog window has been closed.
Why don't you run whatever code you need to run on load final page? It's a matter of architecture. If you need to run code after the user is done with something, run the code before the final page, for instance when they press submit.

HTH

Philippe
0
Tpaul_10Author Commented:
How about something like this.

<script language="JavaScript" event="onbeforeunload()" for="window">
<cfinclude template="act_Cancel.cfm">
</script>

This is working all the time(i mean whenever I move away from this page), but I need to get it worked
only when the window closed.

I need to find out how to use window.close function.

Any suggestions?
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Philippe DamervalSenior Analyst ProgrammerCommented:
Here's a link to a page where they seem to do this. It should apply t you despite the forum being .Net - let me know.
http://forums.asp.net/p/1204326/2226025.aspx
0
gdemariaCommented:

On before load does execute on every page, it's not applicable here.

It seems that forum is being driven by the click of a form button or link, not clicking the browser close button.

I have seen this question again and again on EE, never seen an answer.  I think you need to rethink it.  If you have clean-up to do, consider onSessionEnd()

0
Tpaul_10Author Commented:
Thanks for the reply guys and I am looking in to all these options

gdemaria: Can you please give me an example how to use onSessionEnd()?

Thanks


0
gdemariaCommented:

Are you using applicaton.cfc or application.cfm ?  You need to use application.cfc if you're not, you would have to switch.

The function inside application.cfc called onSessionEnd simply fires whenever the session expires.  It will run whatever code you have in there.

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=AppEvents_11.html

What is it you want to do when the session expires?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tpaul_10Author Commented:
Unfortunately, I am still on CF 7 as well as not using CFC at all since it is a old website which was developed USING CF 5.0.

0
gdemariaCommented:

 Application.cfc is supported by Coldfusion 7

 What is it you want to do when the session expires?
0
Gurpreet Singh RandhawaCEOCommented:
Well! I am asking same scenario from @gd when i struck with a problem like yours using the OnBeforeUnload Event, but i suggest you this is not a valid solution!

You must use onSessionEnd as this method has many advantagaes and javascript is not the only solution
0
Tpaul_10Author Commented:
Thanks for the suggestion experts and i have changed the architecture to work differently.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.