wood burning stoves 2.0*
The moose likes Servlets and the fly likes close browser window! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

close browser window!

Ashok Mudgapalli
Greenhorn

Joined: Jun 24, 2003
Posts: 13
Can I close a browser window auomatically after posting to the servlet? Right now what I am doing is... after posting to servlet, I am redirecting the response to a jsp which has window.close()in <body> </body>. I am not sure whether this is the best way to do. I appreciate your feedback very much.
Thanks
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
use window.close() command in the jsp itself, just after submitting to the servlet ... write this in a javascript function, say fnSubmit(), which will be called upon pressing the submit button.
something like this --->
function fnSubmit(){
...
......
document.forms[0].action = /servlet/TestServlet
document.forms[0].submit();
window.close();
}


- Varun
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Hmmm, I wouldn't close the window on the submit. That makes it impossible to report any errors that might occur during processing of the request.
Why do feel that you need to redirect? You can emit a window.close() as part of the response of the servlet.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ashok Mudgapalli
Greenhorn

Joined: Jun 24, 2003
Posts: 13
You are right, I would like to report any errors before I close the window. In my case, I use servlet to save the user's data to database. After successful save, I would like the servlet to emit window.close() response.
How I can emit a window.close() as part of the response of the servlet? Could you please provide some details?
Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

I guess I don't understand what it is you don't understand...
When you are creating the response, you are creating an HTML page, no? Just make the window.close() part of that page.
Are you having trouble figuring out how to format the HTML?
hth,
bear
[ June 26, 2003: Message edited by: Bear Bibeault ]
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
Originally posted by Bear Bibeault:
Hmmm, I wouldn't close the window on the submit. That makes it impossible to report any errors that might occur during processing of the request.

In a work flow like
Parent page --"click button"--> Pop-up window
--"from pop-up some kind of updation"-->
Result on Popup --and close the pop-up with refreshing parent page --!>
This scenarion will contain the code I suggested. :-)
-Varun
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
Originally posted by Ashok Mudgapalli:
You are right, I would like to report any errors before I close the window. In my case, I use servlet to save the user's data to database. After successful save, I would like the servlet to emit window.close() response.
How I can emit a window.close() as part of the response of the servlet? Could you please provide some details?
Thanks

After you have saved the data.
Use
RequestDispatcher rd = getServletContext().getRequestDispatcher("/Confirmation.jsp");
rd.forward(request,response);
in your servlet to direct the request response to confirmation page, say, confirmation.jsp page.
Where confirmation.jsp will be used to display your result.
Put this simple line in your confirmation.jsp to close the window
------------
<a href="javascript:window.close()">Click here</a> to close this window.
------------
Ashok Mudgapalli
Greenhorn

Joined: Jun 24, 2003
Posts: 13
Hey friends, Varun and Bibeault, Thanks for your replies. It's not the question of understanding the HTML. Nor I am new to html markup language. Here is my issue once more.
The window I am talking about is opened after clicking on an outlook email message (Intranet). This jsp gets created after the link posts to a servlet. This will become my main window. User enters some data on this jsp and submits to servlet. At this point I would like to close this window after successful completion of save.
I have been trying to do window.close() after successful submission but it opens a dialog asking the user "DO you want to close the window....?".
My issue is.. when ths user submits jsp to servlet, the response should close the window without any dialog box (assuming there is no error).
Again Thanks to both of you for your suggestions.
Ashok Mudgapalli
Greenhorn

Joined: Jun 24, 2003
Posts: 13
I found an answer. Here is what I am doing.
I redirect the response to a simple html, this html will have simple javascript code. This code first changes the history of the browser by using location.replace() method to current url. Then I do window.close() which closes the window without opening any dialog box.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: close browser window!
 
Similar Threads
problem with browser Listener in linux
Firefox 3.5 Browser window close using javascript
Modal window and its side-effects
Prevent Duplicate Logins
How to control browser instance per URL?