Resetting wait cursor in browser with Content-Disposition:attachment
The following code works nicely:
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
function InitializeRequest(sender, args) {
document.body.style.cursor = 'progress';
}
function EndRequest(sender, args) {
document.body.style.cursor = 'default';
}
</script>
When the response returns an attachment, though (a PDF from the ReportViewer control, for instance):
Response.AddHeader("Content-Disposition", "attachment; filename=some.pdf")
EndRequest() never fires and the "progress" cursor is not reset. A Javascript call, e.g.
ScriptManager.RegisterStartupScript(this, this.GetType(), "close",
"parent.EndReque开发者_开发问答st(...);", true);
would do the trick, but is not possible because of the content disposition. Can you think of a way to do this correctly - show a wait cursor while a PDF is rendered, and return to the normal cursor when the PDF is displayed? I am assuming a C# context here, but the problem is not language- or platform-specific.
The problem seems to be that the EndRequest function is not being fired. Have you tried to see if the pageLoading and the pageLoaded events are firing?
I have a feeling these events are not firing because there is nothing sent back to the page (the attachment doesn't reach the page the same way an inline document does).
I would move the file download into an iframe. Here is an example of how to do that:
function InitializeRequest(sender, args) {
document.body.style.cursor = 'progress';
var iframe = document.createElement("iframe");
iframe.src = 'your pdf file';
iframe.style.display = "none";
document.body.appendChild(iframe);
}
Then you can access the onload event of the iframe.
EDIT:
Further searching led me to this page. It seems to do all that you're looking to do.
精彩评论