Reputation: 335
Is there any way I can detect opening of the download file dialog box on web pages like hyperlink click event occurs and download file dialog box appears?
And can I edit the filename in it? Like attaching some website name along with filename, so when the user downloads any file, it automatically renames it to website-filename.pdf, etc., programmatically
Can we use input tag for it? Or do I have to make a custom control for it?
Upvotes: 0
Views: 712
Reputation: 3792
In regards to editing the filename:
HTML5 introduces a new attribute for a
tags: download
.
Using it forces browsers that support the attribute to prompt for a file download, rather than navigating to or attempting to open the linked file.
Also, whatever you value you assign to download
will replace the file's actual name.
Source and demo: http://updates.html5rocks.com/2011/08/Downloading-resources-in-HTML5-a-download
Upvotes: 1
Reputation: 116180
You can send a Content-disposition header to force a file downlaod box and specify a default filename.
http://support.microsoft.com/kb/260519
Upvotes: 2
Reputation: 12618
You can just make a hyperlink with its href to a regular file, your browser will prompt to download it.
As for renaming the file, all you could do is create a special page which sends the file contents and correct headers, and specifying another name. You'll have to send the content-disposition
header, as such:
Content-disposition: attachment; filename=yourfilename.extension
Upvotes: 2