473,385 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

onbeforeunload and servlets

Hello:

Can anybody tell me how to detect browser close event in Javascript and how
to call a servlet on a Brower close?

I tried some thing:

<html>
<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">

function unloadMess(){
mess = "message."
return mess;
}

function setBunload(on){
window.onbeforeunload = (on) ? unloadMess : null;
location.href="http://localhost/servlet/ServletPrueba";
}

setBunload(true);

</SCRIPT>
<BODY>
<a href="http://www.microsoft.com" onClick="setBunload(true)">Link 1</a>
<br>
<a href="http://localhost:8080/Version3/pagina2.html"
onClick="setBunload(false)">Link 2l</a>
</BODY>
</html>

But, I want call the servlet only when close browser or I browse to another
web.

Thanks.
Jul 23 '05 #1
1 4285
Derek wrote:
Hello:

Can anybody tell me how to detect browser close event in Javascript and how
to call a servlet on a Brower close?

I tried some thing:

<html>
<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">

function unloadMess(){
mess = "message."
return mess;
}

function setBunload(on){
window.onbeforeunload = (on) ? unloadMess : null;
location.href="http://localhost/servlet/ServletPrueba";
}

setBunload(true);

</SCRIPT>
<BODY>
<a href="http://www.microsoft.com" onClick="setBunload(true)">Link 1</a>
<br>
<a href="http://localhost:8080/Version3/pagina2.html"
onClick="setBunload(false)">Link 2l</a>
</BODY>
</html>

But, I want call the servlet only when close browser or I browse to another
web.


You are trying to "close down" your servlet session to release resources
when the user terminates the browser, or navigates away?

There's no *reliable* way of doing this, but where I work, we've had to
do this because of "per seat" licensing in the back end, and the
connection which is maintained in the servlet session. (Yes, it's
horrible, I inherited it, the back end server maintains a huge amount of
state for each connection, and they don't want to set it up and tear it
down for every request)

We've had to do something VERY ugly...

The application is loaded into a frameset, so the front page just
contains (bear with me, I've forgotten the attributes...)

<frameset ununload="window.open('logout.do','','height=100,w idth=100')"
frameborder="no" rows="*">
<frame src="TheREALfrontpage.jsp" border="0">
<noframes>Tough! We've implented an ugly hack</noframes>
</frameset>

All subsequent pages load into the frame, so the unload event isn't
fired until you close thr browser of navigate that window away.

So, you get a little window popping up when you close the browser or
navigate away.

The logout servlet must send

<script type="text/javascript">
self.close();
</script>

which then gets rid of it.

Of course this is riddle with flaws. If the user opens any of the links
in the application in a new window, these don't have that extra frame.
The use may close the original frame which will log out, and invalidate
the session. The newly opened windows will be orphaned.

Yuck. Horrible. I've tried to implement all kind of other ways.

One way was not using the frame and having *every* page in the app fire
a logout request on unload. The servlet would flag a request for another
page, and ignore that logout if another page in the app was being requested.

Well, on a page *refresh", the onunload is fired before the request is sent.

There is no good way to do this.

Nige

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: lltaylor | last post by:
Hello, Currently I use an onbeforeunload method, to do call various tidy up methods when a user exits my web application - however I now need to add additional support, for users migrating to...
6
by: jennyw | last post by:
Hi, I'd like to use onbeforeunload to submit a form before leaving a page. This works in Firefox and IE. Safari, however, blithely ignores this. Does anyone know of a workaround for Safari? Or...
4
by: sowencheung | last post by:
the bug of onbeforeunload is so obvious! in IE 6 it will popup twice "sometimes" I am using the following code window.onbeforeunload = null; window.onbeforeunload = confirmExit; var...
8
by: drewmania001 | last post by:
im currently using the following to prompt the user before navigating away from the page // add an unload event window.onbeforeunload = bunload; // function to prompt user function...
1
by: David | last post by:
I am using a process to warn users when they leave a page that there have been changes made. I took the example directly from Microsoft example I found in searching for help on the event...
3
by: Bit Byte | last post by:
I have written a custom servlet engine (and "wrapper" servlets) for some legacy code (C/C++) that I have. The servlets contain the bulk of my 1st 2 layers in a 3 tier architecture - i.e. data...
1
Frinavale
by: Frinavale | last post by:
Introduction I've seen many questions asked about how to disable the browser's back button and in the past I've replied with "it's simply not possible". It's not a good idea to disable the back...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.