Make a file open immediately after downloaded by user - javascript

Currently, I have a link to download a file on an HTML page. If clicked on, it asks the user if the user is sure they would like to download the file, and after the user clicks on "yes" it downloads the file. Is there a way to make it open the file immediately after the user says "yes"?
As things are the user has to go into their downloads folder and click on the downloaded file. Then the computer asks the user if the user is sure they would like to open the file. I'm just trying to eliminate these last two clicks to make things more convenient for the user.
Perhaps there's some kind of script I could run once the user decides they want to download the file? I'm open to any approach you guys may have.

This is a security measure you cannot bypass, and is done for the client’s own security. There’s no way you can achieve this (well, perhaps on IE with an ActiveX control, but that won’t cover 100% of the cases).

Related

"Save As" Dialog box when downloading a file on web browser

I need to open an "Save As" dialog box where the user clicks on a link in the browser. The save as dialog needs to display the client system folder structure (Dialog similar to save as in word, excel, etc)
I did refer some similar question related to it. But often the downloaded file gets save in the Download path set by the client.
I don't want to use ActiveX control and looking to do the same using Javascript
Is it possible to open a "Save as" dialog using javascript and save the download file to that specific path in the local client system.?
If this is not possible, which most of the article has pointed out. They state that its not possible due to security. But they don't clearly point the reason (what is the security problem that would arise by doing so, If there is a restriction to browsers to not perform such operation etc.,)
Is it possible to open a "Save as" dialog using javascript and save the download file to that specific path in the local client system.?
No. You can suggest to the browser that it open the dialog, but you cannot tell it where to default to.
If this is not possible, which most of the article has pointed out. They state that its not possible due to security. But they don't clearly point the reason...
Because people don't read things before they click them. So if I give you a link to a file and want to put is on your drive at C:\Windows\System32\blahblah and I set that as the default in the file save dialog, sadly a significant percentage of people are going to just blindly click Save without thinking through the implications. Modern operating systems (and old *nix ones) try to protect users from themselves by making certain operations privileged, but still, at least on Windows that's usually just another Yes/No popup users frequently say Yes to without thinking.
So best if the browser picks the user's standard document folder, or one they've specifically, intentionally configured, rather than let the web page say where to default to.

Google Chrome extension - download, move and delete files

I am trying o make app for my work (will be used only in my office) and among other things I need way to download file (it will be always one ODT and one txt document which will be initiated by clicking on button by user, on specific page - standard download) from our local server. Those two files are created on server and then sent to download to user which requested it, so that part is simple as any other web page which offers you download.
But after download is finished I need somehow:
1) automatically open ODT (openOffice writer) file, so user can continue editing it. What will happen next is not important...
2) automatically move TXT file to specific folder on users disk (this is needed because that specific folder is monitored by our special printer and whenever printer detects file in that folder it automatically starts printing). Setting default chrome download folder as that monitored folder is not options - so I NEED to move TXT file automatically after download to that monitored folder.
3) After first two actions are finished I need to clean default download folder (foldere where chrome downloads by default) because it would be full of those files and they are not needed anymore.
Now, it would be great if I could accomplish it just with javascript but as I know there is no way to manipulate files on local system without displaying dialog to user - so this is not option.
I figure it out that this part could be done by chrome extension, which is acceptable solution because this application will be used only in my office. But I am not sure how and if it is really possible to accomplish what I want so I need your help.
P.S.
It is important that after user click "Download" on page to download ODT and TXT file, there is no other windows, dialog and other "questions" by browser but everything after that should go automatically.
Thank you!
Yes, you can do those tasks with chrome.downloads API, as long as you can accept a subfolder of the Downloads folder as a target for your printer. You cannot download in an arbitrary folder, I'm afraid.
After a download you initiated with chrome.downloads.download finishes, you can initiate opening it with chrome.downloads.open(downloadId).
You can initiate a download into a subfolder by supplying a relative path to chrome.downloads.download (note the / slash instead of \): printout/file.txt.
You can remember the download id's and clean up afterwards with chrome.downloads.removeFile(downloadId).
Please take note of the permissions you need to add, they are quite fine-grained for this API.

Force ask where save file before download

I have an embedded system with a web server Mongoose, I have to allow the client to download some log files generated at runtime, I have a problem during the download, in practice, the browser first downloads the file and then asks where to save the file .
The behavior is unpleasant because the download takes a few seconds and the client does not understand what's going on.
Is there any option, for example, in the header of the file, to force the browser to ask before making the download where to save the file?
Thanks.
it is not up to you to decide how the client's browser is behaving.
if the browser is set to save the file automatically in a specific place, then there is nothing you can do.
your only workarounds is to either upload your file somewhere and suggest the viewer to right-click a download link that points to the file, it will open the dialog,
or suggest the viewer to change browser settings,
or write a browser extension that does that and offer viewers to install it.

how to make an image link ask the user if they want to download it, instead of displaying it in browser

I have an html page full of images. Currently, each image is a link that opens the image in a new tab. I want that image link, when clicked, to ask the user if they want to save it. How would I got about doing that?
Serve the file with MIME type of application/octet-stream on the server to improve your chances of getting a download prompt to show, but ultimately it's up to the browser to decide what to do.
Unfortunately, that is browser behavior and is something that you can't code directly into your web pages. If the browser knows how to display a file of a particular type (which most browsers deduce from the MIME type and the file extension on the URL, if any), then it will attempt to open it in most cases. It is possible to configure the browser to behave differently, but this has to be done on the client machine by the user of that browser--and is something that you, the programmer, can't control.
You do have some options, though they aren't very attractive. The most straightforward would be to put your image(s) inside of a zip file, which most browsers will attempt to download rather than open by default.

Allow users to only open file but not save them

Is it possible to make user open a file on network BUT DON'T ALLOW them to save it?
When I Filenmae, i get options to Save or Open a file. I don't want users to save that file, they can only OPEN them and read/edit them.
Regards
This is handled by the web browser, not by code. In this case they're hitting the file system directly rather than a web server (so there's no place to override headers or anything like that) and the browser is acting accordingly. I'm thinking the only way to achieve what you seek is to configure the browser to always open the file in the associated program rather than prompt the user. If you're talking about a lot of web browsers, that could be a pain.
Also, since it's opening the file from the user's local file system, they can still save it. Once it's open in the associated program (in this case I'm assuming MS Word), they can save it from there. The only way to "not allow" them to save it in this case would be to remove their write access to the file at the OS level (I'm assuming Windows). This also assumes they don't have administrative rights. Otherwise, you'll want it on a file share on a server or something where you can control access.
But even then, they can just save it locally somewhere else.
It's not possible, unless you also make them open some other program that hijacks the basic saving/opening functionality on their computer.

Categories

Resources