简体   繁体   English

在Response.AppendHeader之后window.onload无法正常工作

[英]window.onload is not working after Response.AppendHeader

I have a loading image which is working fine but when I add a download button to the form and added code 我有一个加载图像,它工作正常,但是当我向表单添加下载按钮并添加代码时

        Response.ClearContent();
        Response.ContentType = "application/vnd.ms-excel";
        Response.AppendHeader("Content-Disposition", "attachment; filename=ssss.xls");
        Response.WriteFile(uploadingFilePath & fileName)
        HttpContext.Current.ApplicationInstance.CompleteRequest();

and I understood that when runs 我知道当跑步

Response.AppendHeader("Content-Disposition", "attachment; filename=ssss.xls"); 

line ,then the window.onload functions is not working can anyone help me Thanks in advance 行,然后window.onload功能无法正常工作,有人可以帮我吗,谢谢

The window.onload is a javascript function. window.onload是一个javascript函数。 The response you are writing now is an excel file. 您正在编写的响应是一个excel文件。

When you set the ContentType http header, you tell the browser that you are sending it an application file, and the browser will prompt the user to save the file to disk. 设置ContentType http标头时,您告诉浏览器您正在向其发送应用程序文件,浏览器将提示用户将文件保存到磁盘。

Your page, and your javascript does not receive an events when the user is prompted or the file downloads. 当提示用户或下载文件时,页面和javascript均未收到事件。

There is no way to remove the loading image on an event if your response is a file. 如果您的响应是文件,则无法删除事件上的加载图像。 You could remove it by setting a javascript setTimeOut . 您可以通过设置javascript setTimeOut删除它。

Refer: setTimeOut 参考: setTimeOut

This will call the function hideImage after 5 seconds. 5秒后将调用函数hideImage Add it to your function that shows the image. 将其添加到显示图像的函数中。

function hideImage() {
    //hide your image
}
window.setTimeout(hideImage, 5000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM