1.前台一个javascript函数:
<script type="text/javascript" language="javascript">
function AAA() {
debugger;
}
</script>
2.后台通过 ClientScript.RegisterClientScriptBlock(Page.GetType(), "aaa", "<script">AAA();</script>");调用它,这样是可以的。
3.但是,如果我加了下面的导出功能时,却无效了。(有3行取消注释就前台JS函数没有执行)
public static string openWindowExport(string strFileName)
{
FileInfo DownloadFile = new FileInfo(strFileName);
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ClearHeaders();
System.Web.HttpContext.Current.Response.Buffer = false;
System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
//System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename="
// + System.Web.HttpUtility.UrlEncode(DownloadFile.Name, System.Text.Encoding.UTF8));
//System.Web.HttpContext.Current.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
System.Web.HttpContext.Current.Response.WriteFile(DownloadFile.FullName);
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();
}
我要的目的:JS函数和导出都能执行。javascript无效导出导致后台不能执行前台
<script type="text/javascript" language="javascript">
function AAA() {
debugger;
}
</script>
2.后台通过 ClientScript.RegisterClientScriptBlock(Page.GetType(), "aaa", "<script">AAA();</script>");调用它,这样是可以的。
3.但是,如果我加了下面的导出功能时,却无效了。(有3行取消注释就前台JS函数没有执行)
public static string openWindowExport(string strFileName)
{
FileInfo DownloadFile = new FileInfo(strFileName);
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ClearHeaders();
System.Web.HttpContext.Current.Response.Buffer = false;
System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
//System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename="
// + System.Web.HttpUtility.UrlEncode(DownloadFile.Name, System.Text.Encoding.UTF8));
//System.Web.HttpContext.Current.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
System.Web.HttpContext.Current.Response.WriteFile(DownloadFile.FullName);
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();
}
我要的目的:JS函数和导出都能执行。javascript无效导出导致后台不能执行前台
ClientScript.RegisterClientScriptBlock(Page.GetType(), "aaa", "<script">window.onload=function(){AAA();}</script>")
你这种写法不好整。。把下载写到一个 iframe 中。
当iframe 加载完毕时,就是文件下载完成时,那么再调用js 方法