Solved

prevent web page from closing before it has finished loading

Posted on 2007-11-30
9
510 Views
Last Modified: 2009-06-12
I have a web page that is opening a connection to a crystal report. When the report window is closed, I am closing the connection. However, it is possible for the user to close the window with the x before it finishes loading, in which case the onunload event never fires, which is where I'm closing the connection. Is there a way to prevent the user from closing the window before it finishes. I'm using a synchronous AJAX call to close the connection. An asynchronous call fails because the calling window is destroyed before it finishes.
0
Comment
Question by:kclilo
9 Comments
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 500 total points
ID: 20386366
kclilo,

No there isn't.  The onunload event is the closest thing offered by html and browsers.  As you have found out that won't fire when the browser is just closed.

Are the users doing this on purpose, despite a notice of the problem or is it just innocent.  Most likely they just don't realize they need to leave it open.  The common fix for this is a clear message stating that the browser needs to stay open or the process will fail.  If the process is real long then people will become impatient but you could redesign the process or break it in parts so the "wait" is not a cause of this.  If the issue is just open sessions or other server stuff then you might consider scripts or procedures to clean the DB, etc up as the server ends the session.

The basic answer though is No.  You can't stop it or even detect it directly.  i do hope the info above will give you some ideas though.  Let me know if you have any questions or need more information.

b0lsc0tt
0
 
LVL 28

Expert Comment

by:chilternPC
ID: 20386377
can you not catch the close window command and shutdown gracefully?
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 20386476
Can you get the window id or handle and check if it exists before trying to shut it down.

mlmcc
0
 

Author Comment

by:kclilo
ID: 20386738
The trouble is, this is a web browser window, how do you intercept when it's trying to shutdown.  I fear that b0lsc0tt is correct, but hasn't provided any solution other than warn the user not to close the page, which I cannot do in this case.
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 36

Expert Comment

by:Zyloch
ID: 20387317
I am not familiar with connecting to Crystal Reports, but is it through server code? If so, it does not automatically release the connection if the connection is lost?
0
 
LVL 28

Expert Comment

by:sybe
ID: 20387423
If I understand you well, then I don't see the problem.

Each page is a separate application. To the server each (asynchronous) call made by the javascript is a separate application, which requires its own connection to be opened and closed.

You can not send a connection along with an asynchronous javascript call. You can only send some parameters.

So each page that you create and which uses a connection should first open a connection, do things with it and then close the connection again. You can not close a connection by an asynchronous javascript call.

Maybe I misunderstand the way you are working, but if that is so, I am very much interested in how you manage to close a connection which was opened by a different call from the client.
0
 

Author Comment

by:kclilo
ID: 20388412
Thanks to everyone that is trying to help me solve this.  Here are some more details to help clarify the problem. When I say connection, I don't mean a DB connection, I'm talking about a logon to the Crystal XI report server. The logon takes place in a JSP page and is a call to the server which returns an enterpriseSession object. After logon a report is returned in a Crystal Viewer page which is wrapped in an open.window() call. The enterpriseSession object is stored in a session variable and is accessible when the window closes by doing window.onunload=doLogoff(). This all works fine unless the user closes the window before the report has finished loading. This happens because the logon has been established to Crystal, but the onunload code never gets called to logoff from Crystal. Because of the way the licensing works, we are trying to logon and logoff for each report viewing so that concurrent users can run reports without getting locked out. I don't know why Crystal is not able to release the enterpriseSession when the report window is closed. The only way it will get released is after a 15-20 minute wait. It's looking like I'll have to monitor those sessions by user/pwd and release/reuse them  myself if the same user tries to access another report. It just seems like there should be an easy way to prevent the user from closing the window before it finishes loading, or fire my logoff code regardless, which would solve the problem. Thanks again for you help!
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 20388449
Poke around a bit and see if there is any way to set a timeout less than 15-20 minutes for inactivity. If not, you can keep track of it yourself through a table in your database. If you have enough users, you can log other people off for inactivity through your other users' activities.
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

New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
This video teaches users how to migrate an existing Wordpress website to a new domain.
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…

930 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

10 Experts available now in Live!

Get 1:1 Help Now