Force file download a href






















Active Oldest Votes. Drawbacks: this is exactly what we are trying to avoid! Improve this answer. My workaround: download an image to canvas, then download canvas image to the local drive. Nick Nick 8 8 silver badges 25 25 bronze badges. Don't forget to press "accept answer tick" if my code works for you! So the file saved to disk is different from what I'd get from right-click Save As Its an image captured from a canvas.

To change name or extension you need to modify a code to get them from the URL, or any other source, as you would wish. But testing in more detail, you could blame me for that this workaround wont work with GIF files. I will point this out in my answer too, so that for somebody to come up with a better solution to mine, he has to know whats wrong with it. Meanwhile I'm looking at ways to have my webapp download the bytestream from the external link server-side my server will fetch the file from the external link and then when done, serve it to the client as a local file now hosted on my server.

Not a very good solution as it creates a bottleneck on the server and doubles the data usage. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Who owns this outage? Building intelligent escalation chains for modern SRE. When you Copy Link on modern pages it give you a long string of stuff.

Something like this:. This link will open the file, either in a Web App or a Desktop Application, depending on your settings. To make the link download you need to remove some things from the copied link. Once you paste the copied link into a hyperlink or button or whatever, just remove all text after the?

Something like the below:. Tony Tony 3 3 silver badges 9 9 bronze badges. This worked well, since I had a particular document directory for downloads. I omitted the ForceType, just to let the types stay as-is. I also didn't need the case-insensitive; mine seems to be case-insensitive already.

This worked wonderfully, even in OSX Safari, where as other answers including the accepted one, as one commenter pointed out there are limited to certain browsers which support the given HTML feature.

This one seems more ideal to me since it worked across the board, though it does require higher-level access to the server configuration files.

You could put that right in your apache. How would a Windows-hosted web site implement this, since they can't read htaccess files? User User 1 1 silver badge 4 4 bronze badges. Turns out the file needs to be local in order for it to work. My href was a url to cloud storage. Ashay Ashay 4 4 silver badges 13 13 bronze badges.

This appears to be a nice way to serve up every single file on your server to anyone who's paying attention. Try adding this line to your. Sharad Gautam Sharad Gautam 89 1 1 silver badge 1 1 bronze badge.

I'd be interested to know why this has been downvoted - it's one of the simplest methods and works: css-tricks. People try to modify the core functionality of a server on free hosting sites and then downvote because they can't get it to work. Every other solution will have caveats because it is a "hack" to replace this. I'm downvoting it because it's the wrong solution to the problem. It's a bad idea to mess with types of resources.

NathanHornby - I didn't downvote it, but this would not work for any Windows hosted site, since they don't use. I didn't downvote, but this solution blindly affects ALL files of that suffix. It's indiscriminate and therefore won't be appropriate in all cases. I just used this, but I don't know if it works across all browsers. That is suggested, and with more background information, in an earlier answer.

Bungle Mr. Bungle 1, 16 16 silver badges 21 21 bronze badges. Terrible usability. Many end users wouldn't know what to do with a zip file. Sometimes simple solutioans are the best solutions! Not a good solution. I have exactly that problem with Firefox and a ZIP file.

What should I do? ZIP the file? Just put the below code in your. Doesn't this presume the web server is Apache? This is old post but here is the one my solution in JavaScript what using jQuery library. JJxyz JJxyz 10 10 bronze badges. Remove the Meta Content-Disposition;Inline; which will open the document in the same window In java it is set as response. BJ5 BJ5 4 4 silver badges 19 19 bronze badges. ByteHamster 4, 9 9 gold badges 35 35 silver badges 51 51 bronze badges.

Bonnie Bonnie 9 1 1 bronze badge. That's hard to achieve because it's the server that sends the mime type and when linking directly to a PDF file, you cannot change the headers. You also need to set your servlet in web. Ariwibawa 7 7 silver badges 14 14 bronze badges. Aviv Day Aviv Day 3 3 silver badges 11 11 bronze badges. Joojoo Joojoo 1. The Overflow Blog. Who owns this outage?



0コメント

  • 1000 / 1000