Link to home
Start Free TrialLog in
Avatar of kclilo
kclilo

asked on

prevent web page from closing before it has finished loading

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.
ASKER CERTIFIED SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
can you not catch the close window command and shutdown gracefully?
Avatar of Mike McCracken
Mike McCracken

Can you get the window id or handle and check if it exists before trying to shut it down.

mlmcc
Avatar of kclilo

ASKER

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.
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?
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.
Avatar of kclilo

ASKER

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!
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.