473,386 Members | 2,078 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,386 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 4286
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.