2

我正在使用代码从弹出窗口中导出 pdf 文件。

点击按钮

  function popupReport() 
    {
        var url = 'Report.aspx';
        window.open(url, 'winPopupReport', 'width=300,height=300,resizable=no,scrollbars=no,toolbar=no,directories=no,status=no,menubar=no,copyhistory=no');
        return false;
    }

在 Report.aspx.cs 中

 ReportDocument repDoc = ( ReportDocument ) System.Web.HttpContext.Current.Session["StudyReportCrystalDocument"];
        // Stop buffering the response
        Response.Buffer = false;
        // Clear the response content and headers
        Response.ClearContent();
        Response.ClearHeaders();
        try
        {
            repDoc.ExportToHttpResponse( CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, true, "StudyReport" );
        }
        catch( Exception ex )
        {
        }

该代码在 IE7 中运行良好。但在 IE6 中,弹出窗口没有关闭。为什么会发生这种情况?

4

1 回答 1

0

Some browser deny automatic closing for web pages in some conditions.

Try this workround to close a page.

Write a script, in the page that you want to close, that opens another page; in this sample the script is injected via code after a button click, but you can write it directly in HTML if you need it.

   ClientScript.RegisterStartupScript(typeof(Page), "closePage", "window.open('Success.htm', '_self', null);", true);

Create Success.htm page this way

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
 <head>
  <title></title>
  <script language="javascript" type="text/javascript">
   var redirectTimerId = 0;
   function closeWindow() {
      window.opener = top;
      redirectTimerId = window.setTimeout('redirect()', 2000);
      window.close();
  }

  function stopRedirect() {
     window.clearTimeout(redirectTimerId);
 }

  function redirect() {
     window.location = 'default.aspx';
 }
 </script>
</head>
<body onload="closeWindow()" onunload="stopRedirect()" style="">
   <center><h1>Please Wait...</h1></center>
</body></html>
于 2012-02-24T10:42:46.250 回答