Creating and editing .text file from javascript - javascript

I am making a web site that makes a record of the person who visit it
I have created a html form page that requests the name from the user
But I am unable to figure out how to keep record of it,maybe something like using making a text file and having javascript add names to it,but I am not sure how to do it
I am using Google drive and drv.tw to upload the site so I can't use any server side scripting language

Native JavaScript has not access to user's file system. But Node.js has, try this one if u can. In native JS you can use something like localStorage. But this solution only for your task, do not use this for production...

Related

How to use html5 geolocation in the background for java web application

I have googled around attempting to find an answer to this question, but I have had no luck so I will ask it hear in the hopes that one of you can help!
I am attempting the use the javascript method navigator.geolocation.watchPosition to continuously gather location data.
The scenario is that I have a java web application using servlets and jsps, and I would like to begin geolocation collection when the user logs in, and stop when the user logs out. The data would be uploaded to a sql database after being collected. I have successfully been able to collect data for a single page, but I don't know how to implement a solution that works across all pages in the application.
I appreciate any and all help, thanks!
Since you are developing a Java web application, I would suggest
Extract the JS logic that tracks user location from the JSP page, into a separate JS file or JSP file (if the script is generated dynamically).
Use a Servlet filter to add a reference to this tracking JS file into all HTML pages returned to client. You may use Regular Expression to search in the HTML content, insert <script src="url to tracking JS file"> right before </head> tag.
The filter doesn't need to inject this script reference if it finds current user hasn't logged in yet.

How can I use session specific data files in javascript

I am creating a web application using Ruby Sinatra. However, I think this question is more related to html/javascript.
In the front end I am using d3.js for some pages. I want to create and use data files based on user input. So for each user session I want to create a data file for that session.
I think I can create the custom html/javascript for each request.
Is there any other way to do this, such as passing the file name to the javascript?
You can use sessionStorage (some examples is here http://www.nczonline.net/blog/2009/07/21/introduction-to-sessionstorage/)

Can I use PHP SDK and JAVASCRIPT SDK at the same time?

I have a php program/app which asks for input, generate an image and post th image link to user's timeline (processor.php). I used PHP SDK in posting to timeline since I am more familiar with PHP. Now, in my gallery.php, i want to show like buttons for each generated image. I am aware that i have no option but use JS SDK in making button. but is it fine if i use two different SDK's in a single app?
processor.php - PHP SDK
gallerry.php - JS SDK
thanks for your answer! I would love to try your suggetions too
There shouldn't be any problem using PHP and JS in the same application, quite a common use case. You would normally use PHP to create the Web Application structure, handle backend logic, and then use JS to handle UI events.
There's nothing special about combining the two, just create the Web page with JS as normal for the view, and use PHP to build it.
Hope this helps.
Yes, there is no problem, the two APIs are designed to work together. The PHP API is usually used to created the backend logic (for example OAuth implementation, posting and getting data, etc) and the JS API to handle user iniated events.
Also see this: https://stackoverflow.com/a/6728092/1107118 on how to handle login state. Normally the JS API is used for logging in too, and then with the PHP API you take the access token and do the backend actions.

Save text file on client machine using javascript

I want to create text file on client machine and then want to write in that file.
And while saving that file i want to ask user where he want to save file i.e. want to ask by save dialog box....
Thank in advance....
That is not possible with JavaScript for security reasons. You cannot create files on the client machine, since JavaScript doesn't have write permission in that environment.
What you could do as a work around is to send the text that you want to store through an Ajax-request to the web server, which in turn can generate a the text-file for the user to download to a desired location. Not as smooth, but at least it is a work around.
You cannot write back using JavaScript alone. You would have to perform a GET or POST call to be able to prompt a save.
Related question Read/write to file using jQuery
You can do it through flash "proxy" that uses FileReference class and communicating with flash using ExternalInterface
The data I wanted to write is already available at the client side (queried from server) and stored in Javascript arrays.
I have done this using 'Data Tables' which is a plug-in for the jQuery Javascript library. You can store the data in .csv, excel or also .pdf. You can access this nice plug-in at http://datatables.net/

Reading and writing to an external file using javascript?

I have an online storage account that I`m using for my homepage. Basically I have just made an "index.html" and stored there . and no php , asp is possible .
So If I must create a message form on the homepage and store the message in a separate text file in JSON format ,can it be done using javascript ?
also I need to query the Text file whenver I want to display the messages using javascript .
So far , I tried TaffyDB but realised it doesn`t have a way to persist the data after session closes. or maybe I missed something?
Thanks!
Short answer. No.
The JavaScript is client side. So it can do all sorts of cool stuff on the persons computer that visits your site but unless you're running some server side code that takes the JSON encoded data and does something with it then you're out of luck.
There are many alternatives.
If you don't want to run your own server side code then you could use a separate service like Parse.com that does REST and has a comprehensive API.
A mobile website can access Parse data from Javascript.
A webserver can show data from Parse on a website.
You can upload large amounts of data that will later be consumed in a mobile app.
You can download recent data to run your own custom analytics.
Applications written in any programming language can interact with data on Parse.
You can export all of your data if you no longer want to use Parse.
You can try with jQuery/AJAX. To read:
$.get("path_to_file", null, function(fileData) {
alert(fileData);
/* Your code goes here */
}, "text");
But in order to write, I think the only way is with some server-side language (PHP, ASP, etc)
The short answer is no.
You need to have some server-side support to persist the data on that server. You can, however, use client-side javascript to relay the information to a server that DOES support reading and writing of the data of course.
Technically, node.js is javascript that does support file reading and writing - but I assume that's out of the question for your environment :)
One crazy way (just as a thought experiment) to implement persistent storage for your web application without server side support is to have the clients talk to each other through P2P. This is possible with Flash or some java applet..etc. So as long as one client is up (perhaps your own comupter!), you'll have some form of persistent storage. Your server/webpage simply serves up this embedded object which does the actual work.

Categories

Resources