[英]how to reload the parent window while closing popup window when on form submission i am using java class to show the child window content
function printPDF() {
var URL1= '<%=Handlers.getPath(PA.PDF_RH)%>';
var URL2 = "<%=jspBean.getPDFUrlContext()%>/" +
getValue(Obj.value, pdfFile);
URL2 = URL2 + ".pdf";
printFormat = window.open("","_blank","");
printFormat.document.write("<html><head><title>Print Media Queue</title>");
printFormat.document.write("<script> \n");
printFormat.document.write("function submit(){\n ");
printFormat.document.write("alert('Yeah ! I am inside submit');document.forms['myForm'].submit();\}");
printFormat.document.write("function afterprint() { \n");
printFormat.document.write("alert('i am inside After print method')\n");
printFormat.document.write("self.close();\n");
printFormat.document.write("opener.<%=jspBean.FORM_PRINT%>.submit();\n");
printFormat.document.write("} \n");
printFormat.document.write("</");
printFormat.document.write("script");
printFormat.document.write(">");
printFormat.document.write("</head><body onunload='afterprint()'><form name='myForm' id='myForm' action='" + URL1 +"' method='POST' >");
printFormat.document.write("<input type='hidden' name = 'printpdf' value='" + URL2 + "'>");
printFormat.document.write("</form>");
printFormat.document.write("<");
printFormat.document.write("script>submit(); ");
printFormat.document.write("window.navigator.disablePACheck = false;print()");
printFormat.document.write("</");
printFormat.document.write("script");
printFormat.document.write(">");
printFormat.document.write("</body></html>");
printFormat.document.close();
}
我的java課
public class PdfRH { public void doRequest(ControlBlock oSCB) throws Exception {
HttpServletResponse response;
response = oSCB.getHttpServletResponse();
String pdfPath = oSCB.getRequestParameter("printpdf") ;
System.out.println("*********************************************"+pdfPath);
File pdf = new File(pdfPath);
String pdfName = pdfPath.substring(pdfPath.lastIndexOf("/") + 1, pdfPath.length());
ServletOutputStream stream = null;
BufferedInputStream buf = null;
try{
stream = response.getOutputStream();
// PrintWriter pw = response.getWriter();
response.setHeader("Content-type","application/pdf");
response.setHeader("Content-disposition","inline; filename=" + pdfName);
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "No-cache");
response.setDateHeader("Expires", 0);
response.setContentType("application/pdf");
FileInputStream input = new FileInputStream(pdf);
// response.setContentLength((int) pdf.length());
buf = new BufferedInputStream(input);
int readBytes = 0;
/*pw.println("<html>");
pw.println("<head><title>Hello World</title></title>");
pw.println("<body>");
pw.println("<h1>Hello World</h1>");
pw.println("</body></html>");*/
//response.getOutputStream().write(b);
while ((readBytes = buf.read()) != -1)
stream.write(readBytes);
}
catch(Exception ioe){
throw new ServletException(ioe.getMessage());
}
finally
{
if (stream != null)
stream.close();
if (buf != null)
buf.close();
}
}
在按鈕上單擊,我調用一個javascript
函數,並且在該javascript函數中,我編寫了html編碼,在其中創建了表單,並在提交時傳遞了類名和另一個變量,即將讀取pdf
的pdf路徑。在彈出窗口中顯示。
正如我們看到的那樣,整個控件已經進入java類,但是我希望在關閉pdf
窗口時應該重新加載父窗口
嘗試將以下代碼添加到您的Java類中...
String code_windowClose = "<script>window.onunload = refreshParent;
function refreshParent() {
window.opener.location.reload();
}
</script>";
stream.wrtie(code_windowClose);
此代碼會將onunload事件腳本插入到您的子窗口中,該子窗口正試圖關閉打開器(即父窗口)窗口。
請讓我知道,如果你有任何問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.