Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

closing a window from an ActionForward

Status
Not open for further replies.

jstave

Programmer
Nov 18, 2003
2
US
I'm trying to have the current window close if a submit succeeds. It seems to me that I should just be able to have the actionForward specify "javascript:window.close()" but I can't seem to get that to work. All that happens is that I get a 404 error. Is this possible? If I type the javascript into the Address box on the browser, I get the desired result.

If it matters, the exact XML fragment from my config file is:
<forward name=&quot;success&quot; path=&quot;javascript:window.close()&quot; >

I've tried this with redirect true and false, and even with a path of &quot;'javascript:window.close()'&quot; (extra quotes) all to no avail.

Can anyone out there give me a clue?
 
I can think of two way to do that:

1. forward to a JSP page say (closeWindow.jsp) which simply contains a javascript to close the window.

in struts.config you have
Code:
  <forward name=&quot;success&quot; path=&quot;closeWindow.jsp&quot;/>

in closeWindow.jsp you have
Code:
  <html>
  <script language=&quot;javascript&quot;>
     self.close();
  </script>
  </html>

2. in the Action class, you simple output the javascript code to close the window, and no need to forward further.

Code:
public ActionForward execute(
	ActionMapping mapping,
	ActionForm form,
	HttpServletRequest request,
	HttpServletResponse response)
	throws Exception {
		
	PrintWriter out = response.getWriter();
	out.write(&quot;<html>&quot;);
	out.write(&quot;<script language=&quot;javascript&quot;>&quot;);
	out.write(&quot;self.close();&quot;);
	out.write(&quot;</script>&quot;);
	out.write(&quot;</html>&quot;);
	response.flushBuffer();
	return null;
}
 
Thanks. I'd already implemented the first solution, it just seemed to me that, since I can type the javascript into the address area on the browser, that I should be able to use the javascript as the address.

My solution used &quot;window.close()&quot;. Is there any difference between that and &quot;self.close()&quot;? Is one superior in some way than the other?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top