首页 文章

ASP.NET中Crystal Report的问题 - ExportToHttpResponse

提问于
浏览
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中弹出窗口没有关闭 . 为什么会这样?

1 回答

  • 0

    某些浏览器在某些情况下拒绝自动关闭网页 .

    试试这个workround关闭页面 .

    在要关闭的页面中编写一个脚本,打开另一个页面;在此示例中,脚本在单击按钮后通过代码注入,但如果需要,可以直接在HTML中编写脚本 .

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

    以这种方式创建Success.htm页面

    <!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>
    

相关问题