Is it possible to transfer information through js? - javascript

It may not be a good question, but is it possible to transfer local values from a user to a public text file using JS?
For example, I want to write the IP value of a user ( var IP = ... ) to a text file (www.blabla.com/iplist.txt ).

With only JavaScript? Yes. With only browser-based JavaScript and nothing else? No. :-)
You need
A place that stores the file so that when people go to look at it, they can get it (e.g., a server of some kind), and
Some means of modifying the file that that server provides when people go to it, which you can't do from browser-hosted JavaScript
You could use a Node.js-based server (for instance), or some cloud provider where you don't care what the server tech is, but you'll need a server.

Thank you, guys! I will use PHP for that.

Related

How to set a licence-type authorization to a JS file?

I know this is not the right "use" of Javascript. But my company wants to give access to a Javascript file to only particular client (for example clients who subscribe to a special plan). For exemple, if we provide a script to a client and 5 users can access to it, how can i authorize the access to only 5 users and not more?
Because if we don't restrain the access, the client can take the script and give it to anyone (and we will loose a lot of money, because we are selling our knowledge, and our knowledge is this script)
For now the only way to secure our code is by using NodeJS, so the client can't see the script because he only see the generated html page. But we can have the case which the whole server is hosted by the client. So anyone can access to the script, and we want to prevent this case.
So, is there any way to setup a server licence-like for a web application?
(I already know about JS minimizer, and obfuscator, but this is not the kind of things I m looking for)
Thanks in advance
JavaScript is a client side script language, that means it's hard to protect your knowledge.
Even if you minimize or obfuscate your script, people can send it to others and it'll still work.
Inspired by video protecting, I have an idea to protect your knowledge.
You can insert a log script that send logs with your custom's id. If your custom share the script to others, you can know it.
Another way is to insert a fragment of useless code, which can track the custom id, like:
var userId = zo1vjiw73;
Then if you see some other website are using your code, you can easily know who shared the script.

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.

Storing data securely in javascript (autosuggestions)

How can I store data on the clients side securely (not viewable/visible) in javascript.
In particular, I want to grab an array from the database with PHP and then use that array for autosuggestion data. Currently I am setting the array as a JS variable, however it can be seen in the html page source code.
I have looked at autosuggestions online and came across: http://www.brandspankingnew.net/specials/ajax_autosuggest/ajax_autosuggest_autocomplete.html
I cannot find where the autosuggestion data is being stored, which is what I want for my script. Help!
No, what you are trying to do is impossible. Javascript is being run by the client and thus the client has absolute control over the data. If you are trying to store a secret in javascript then an attacker can use a debugger to see it in memory. But this is the worst case. Its easier a lot easier to manipulate the traffic with TamperData, or manipulate the javascript directly with Greasemonkey.
If it is sensitive data like usernames or passwords, you shouldn't auto suggest anything. If it is not sensitive data, the AJAX solution from your link is the obvious way to go, but you could easily store it in a cookie if it is not more than 4kb, or in various cookies otherwise.

Server-side access to Client Browser's Latitude/Longitude using Django

So i am writing a little app that compares a user's position against a database on web-based server written
using Django and performs some functions with it.
Accessing the browser's geolocation data (in supported browsers ) is fairly trivial using JavaScript. But what is the best way to allow
the Django server to access the longitude and latitude variables? Is it best to wrap them up as a JSON object and
send to the server via POST? Or is there some easier (Geo)Django-based way to access the Navigator.geolocation browser
object.
Please forgive a newbie a question like this, but my Google-Fuing only seems to find ways to insert variables into
JavaScript via template tag, whereas I need it to work the other way!
Any advice or code snippets greatly appreciated. Feel free to talk to me like I am an idiot.
You will indeed need to POST your location data to a Django view.
If all you need is simple distance calculations, take a look at Geopy.
If you want to interact with the ORM and filter/search based on location, you'll want to look at GeoDjango.
Navigator.geolocation is only available on the client side. You'll have to send the data back to the server using Javascript, such as via a POST (as you surmised).

Categories

Resources