Reputation: 16903
I am downloading a file using the code
btnDownloadTemplate.Attributes.Add( "onClick", "window.open('StudyReport/WordReportTemplate.doc', 'OpenTemplate', 'resizable=no,scrollbars=no,toolbar=no,directories=no,status=no,menubar=no,copyhistory=no');return false;" );
This will show a popup and the download dialog is shown. How can I avoid the popup and only the download dialog is on the screen?
Upvotes: 3
Views: 12209
Reputation: 138017
A common trick is to open the link in an <iframe>
. This doesn't require JavaScript, and won't open popups or blank tabs. The <iframe>
can be very small, so it's almost invisible.
<iframe name="DownloadDummy">
</iframe>
And the link:
<a href="http://example.com/file.csv" target="DownloadDummy">Download File</a>
Upvotes: 2
Reputation: 1104
Also, you can just use window.location instead of window.open.
var file = 'StudyReport/WordReportTemplate.doc'; window.location = file;
Upvotes: 1
Reputation: 16903
I got the answer. I remove the Attributes and add the click event and in it.
string path = Server.MapPath("");
path = path + @"\StudyReport\WordReportTemplate.doc";
string name = Path.GetFileName( path );
Response.AppendHeader( "content-disposition", "attachment; filename=" + name );
Response.ContentType = "Application/msword";
Response.WriteFile( path );
Response.End();
Upvotes: 3
Reputation: 46425
Don't do a Window.Open, just change the URL of the page to be the document.
Upvotes: 2