Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

close browser window!

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
 
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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();
}
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
 
Ashok Mudgapalli
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Posts: 1400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

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
Posts: 1400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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.
 
No matter how many women are assigned to the project, a pregnancy takes nine months. Much longer than this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
    Bookmark Topic Watch Topic
  • New Topic