Solved

prevent web page from closing before it has finished loading

Posted on 2007-11-30
9
509 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
date format angularjs2 16 43
Javascript Refresh Parent Page from Popup 3 27
getting id from database 5 24
Test ddwrt:UserLookup 1 23
Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

760 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

18 Experts available now in Live!

Get 1:1 Help Now