To Close Browser Window in servlet


Web tier: servlets, JSP, Web frameworks: To Close Browser Window in servlet

  1. I have a down load servlet in which file download is performed by the following lines od code


     response.setHeader("Content-Disposition", "attachment;filename=" + name +";");

    then i say

    PrintWriter out = response.getWriter();
            out.println ("<script>");
            out.println ("window.close()");
            out.println ("</script>");

    .But Window is not closes.Could any one tell me what the problem might be!.and is there any way to close browser window.
  2. It will be better if you try the following constuction:

    <BODY OnLoad="javascript:parent.window.close()">
  3. Dear,

    Calling Javascript like this is not recommended. You need to trigger an event to call the java script. If you are using some event to close the window then call a function on that event and call this method ( window.close) in that function. It will surely work ..

    Just like


    function close_wind()
      // all event operations
      window.close ;