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.
Related
As far my knowledge we can't change the UI of file popup box(window which we open to choose file from computer).
<form>
<input type="file" name="pic">
</form>
I know we can't do that however, is there any way we can change look and feel of that popup box(window).
For better standing I have attached the image of window of the file upload pop box.
No! you can not, that is managed by Operating system, and we can control only browser(if browser allow this by JavaScript APIs/HTML/CSS).
There is only one tricky way, to design our own file-browsing by JavaScript, but that can raise security problems and all browser set it disabled by default.
On such type of JavaScript browser ask from user to allow access to local file system each time(per browsing session). I suggest you not to do so, you should use it on local system for study purpose only.
One more thing that will also not work on all devices/OSs/Browsers. (Once I have accessed local drive by JavaScript ON internet explorer and windows 7 OS, I am not sure about others.)
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).
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.
In my web app I need to give the user the option to save a js variable as a file (when the user clicks download, the app offers him to save a file, preffereably as .js file).
Similarly as google docs offers you to save a file.
Is it possible for javascript to pass it's variable this way?
Check out Downloadify which allows exactly this.
Downloadify is a tiny JavaScript + Flash library that enables the generation and saving of files on the fly, in the browser, without server interaction.
it requires Flash installed in the user's browser to work, though.
I know of no other way of doing this without server interaction.
You might also want to check out OpenSave:
http://www.gieson.com/Library/projects/utilities/opensave/
... which looks much like Downloadify, but seems to have a few extra features (and not as complicated?).
I need a Javascript sample which reads contents from a url and creates a file in the client with same contents when some button is clicked. I also understand that Javascript cannot be allowed to access the local file system (Unless you use ActiveX objects). I do not want to rely on ActiveX objects (since my client is not IE always).
So here is what I did. I used the standard XmlHttpRequest made a request and got my bytes. Now I thought I could kinda stream this contents to the user, first by opening a standard dialog box (the box that pops up when you attempt download something from internet with options like Open/Save/Cancel) and then asking the user to save it somewhere.
I know how to do the read part, can someone show some javascript/html sample on "How to stream open a confirm dialog box to the user and stream some contents?"
PS: Not too sure if this could be done in javascript at all but with Javascript you never know what is possible and what is not :)
Rather than using Javascript to stream the content, which is not possible for obvious security reasons, you need to point the browser at a URL that will return a 'Content-Type' header of 'application/octet-stream'. In most cases this will force the browser to initiate a 'save as' operation and ask the user what to do with it.
I believe it is possible to do this using an iframe in the same page, such that the user will not have to navigate away from the page or open a new tab/window.
See it this way: if you could read/write to users' computers using JavaScript, then no computer would be safe from browsing the web.
Having said so, you cannot read/write client-side files using JavaScript.
But you could if you use Flash / a Java applet; in those cases the embedded objects asks for your permission before doing such actions.
You may want to have a look at TiddlyWiki that claims it can write itself to the disk...
If I understand what your question is, then you want to use JavaScript to write data like a server-side script would (PHP, Python, Java, etc..) but in browser?
If so, then what your asking isn't possible with in browser JavaScript.
However if for some reason you wanted to do this with server-side JavaScript, then yes the "streaming" part is possible.