Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Catch browser's close window event  RSS feed

 
Evangelos Papadakis
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm trying to add the following functionality on a JSF UI project:

I want to catch the event when the user wants to close the browser window and in that case, give an alert message.

I'm searching everywhere but so far I didn't find anything.

Thanks in advance for any help.

 
Christian Nicoll
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Evangelos,

I think that the first thing to find out is how the detect in JavaScript when a browser should be closed. This piece of code will be not trivial if want to make sure that you component should work under several browsers and also in different versions of them. I would also assume that you don't 've to reinvent the wheel, because some would 've solved this problem before.

After you know which piece of JavaScript code you need, then you write just a simple custom component which writes the required JavaScript into your generated HTML. If you just want to inform the user by a simple (JavaScript-)Message then you need also to include an alert()-Statement in your custom tag.

Good luck,
Christian
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect this is one of those "I want to do X, so I will do that by doing something when the user closes the browser, but how do I do that" questions.

It's usually better to ask how to do X, rather than to ask how to do something else which you don't know how to do. So what's X in your case? There really are very few use cases for knowing when a user closes the browser.
 
Evangelos Papadakis
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, actually our customer, when works with our intranet application, they want to open for a while an other application from desktop, they sometimes close the browser with the 'x' (just to see the desktop and launch some program), after that, they don't find any more the browser with our app to continue their work... (obviously !) ..I want only to put an alert on 'x' pressing in order to advise because some of them they think that our app is not compatible with that program... (public administration users... no comments ) .
...for now we decide that we cannot do that. But anyway, many thanks for responding...
P.S. Paul, in this case, X is close the browser... "usually" can remain "usually" and not "always"
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!