2009-06-10 61 views
2

我正在使用代碼從彈出窗口導出pdf文件。ASP.NET中Crystal報表問題 - ExportToHttpResponse

在點擊按鈕

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中,彈出式窗口未關閉。爲什麼發生這種情況?

回答

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>