I want create a test web page but i have stuck on something. At my web page i want to place a link button so that when a user visits my web page and clicks the button , will be able to download an image. I know how to create a link (<a href="pathname">Text</a>) but it just show the image. I want an image,file w/e to be downloaded when the button is clicked. How do i do that help please! Appreciate your help.
Sorry my mistake..
What i really meant was that when a user clicks the button , it would appear a window saying save or save as.The user then choose to save it anywhere he wants to or a default place. Like we do in other web pages when we press a download button.Hope you get what i mean.Sorry for this my english are not so good... Appreciate your help!
Location: Splendora, Texas, United States of America
Thanked 187 Times in 184 Posts
Originally Posted by Dravener
I want an image,file w/e to be downloaded when the button is clicked.
Since you mentioned "Html5": The HTML5 mechanism for doing this is the download attribute:
Originally Posted by WHATWG HTML
The download attribute, if present, indicates that the author intends the hyperlink to be used for downloading a resource. The attribute may have a value; the value, if any, specifies the default filename that the author recommends for use in labeling the resource in a local file system. There are no restrictions on allowed values, but authors are cautioned that most file systems have limitations with regard to what punctuation is supported in file names, and user agents are likely to adjust file names accordingly.
Assuming that you don't want to specify a custom download file name, your code might look like:
<a download href="image.png">Download Image</a>
So far, this feature is only supported in Chrome 14+.