Using javascript with a local html file to delete itself? - javascript

I coded a local html file that kind of works like windows notepad would, using localStorage with JavaScript to auto save. To make new notes, I have just been saving the open file as another .html file and naming it something new for the note. But I have found this to be really annoying, because when I want to delete the note, I have to actually go into my Files app, find the .html file for the note, and delete it.
I know how to use event listeners and whatever, but is there a line of code I can use to delete the file or even just ask the user for confirmation to delete the file? I basically need a way for a local html file to be able to delete itself using JavaScript. Everything I have managed to find online says that you need Node.js and it has to be on a server, but I wanted to ask anyway, because I wonder if permissions are different when the file is stored locally and not on a server.

No.
You can't use browser JavaScript to manipulate the real local filesystem. (You could access a sandboxed one, but not the real filesystem.)

Related

Save canvas to an image file dynamically

Is there a way to download a canvas image to a file folder without a prompt showing up? I have found solutions requiring a prompt where you name the file, but I have not found any solutions where you can dynamically name the image and save to a local file. I am very new to front-end development, so I am not entirely familiar with Node.js or JQuery/PHP/Ajax. I have found solutions using these but they have ended up still using prompts.
In general, this is a security feature.
You don't want a site you browsing to save files to your computer silently. They can possibly contain a malicious code for example, or override an existing file. Thus, as a security feature the browsers are asking you to name the file you will save.
There is a way to name the files thou, so you don't need to present the user with generic file name.
On How to do that - it really depends what are you using to do it..
In your situation - if those are log files you want to save - you can send them back to the server. That can be easily done.

Detect local changes of JavaScript code

I have a website (game in JS). I would like to know if it's possible to detect if some client has edited and saved JavaScript file locally. My idea was to send the entire (or probably just part, it doesn't matter right now) .js file as POST parameter, so that PHP could compare it with .js file on server.
I've searched for local modifications, mutationobserver etc. but I haven't found the way.
Also, can JS file read itself?

Save files into selected directory (javascript)

Hello! My question is about javascript.
I want to
1. ask a user to select a directory
2. then write my bunch of files to it (probably with creating sub-directories) without interaction with user
How can I do this? And can I?
I am new in javascript and I hope for your help.
PS.
I've heard about ability to ask a user to select a path by save file dialog and then save data to selected file, but i want to ask a user once for selecting a directory and then create a bunch of files in it without bothering a user for each one.
Javascript alone doesn't have any way to access the local computer's file system for WRITE purposes. Period.
However, Downloadify, by Doug Neiner, was built for this purpose and uses a combination of Javascript and the Flash library.
It needs Flash 10 to work.
Alternately, you can install apache onto the computer (or better yet, a full stack like XAMPP or WAMP/MAMP/LAMP) and use PHP (with javascript/ajax) to write files onto the local file system. However, this means that the website must also be hosted locally. Probably your best bet is Downloadify
Resources:
https://github.com/dcneiner/Downloadify
How to create xml file with jquery
Save content using Jquery? Write to file
Saving to server-side file using AJAX

How can I let users upload files by copy/paste?

I'm trying to create a web app based on ExtJS, and I'm working on the file-upload area of the app.
I want users to be able to upload files by copying and pasting them - not just copying and pasting the contents of the file, but the file itself. For example, in Windows, you can choose "Copy" or "Cut" from the Edit menu while a file is selected, then choose "Paste" later and copy or move the file - I'd like users to be able to upload files to my app in the Paste step, by just choosing Paste in their browser.
I've already tried HTML5's drag-and-drop API, but we don't want to use that - we want users to be able to copy/cut and paste files to upload their files (as long as they're smaller than 20 megabytes). If the user copies the path to their file and pastes that directly to the page, telling us where to find the file, that could also work.
Can anyone suggest a way to do this?
The thing is, that you're not able to access the clients filesystem with javascript. There is this new Filesystem API, but this just allows you to create a virtual sandboxed filesystem. I had the same problem, thought about it a while and came up with the following ideas.
Flash
Writing a Flash bridge which access the filesystem and let the javascript communicate with it via swliveconnect
Problem: Flash doesn't have filesystem access either.
Java applet
Same thing as Flash and again with LiveConnect
In my opinion this could work, but I didn't try it out, because my goal was to get filesystem access on a chromebook. And chromeOS doesn't support Java (at least without some hacking)
ActiveX
I also found some solutions with this. I gave up at the applet part so I didn't try this out either.
As Jared Farrish said, when you copy a file the os just saves the path to the file in the clipboard. Then if you receive the paste event on your webapp just get the string out of the clipboard and forward it to your file bridge.
I've seen that DropBox.com allows this to be done (in chrome- didn't seem to work in IE). I didn't do cut and paste specifically, but dragged files into a dropbox page from a local folder, and it uploaded the files. So, this doesnt directly answer your quesiton, but perhaps you can look at how this is done in their code.

Open a save file dialog for a js variable

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?).

Categories

Resources