?
Solved

prevent web page from closing before it has finished loading

Posted on 2007-11-30
9
Medium Priority
?
520 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
8 Comments
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 2000 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 29

Expert Comment

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

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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
Suggested Courses

862 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