Creating a Javascript local application(ran in browser)? - javascript

I'd like to write an application that would use both Javascript and HTML as for the user interface. The app wouldn't really need an internet connection but will need access to the user's local files.
My first thought was that this would be impossible in a browser due to the security restrictions on the access to local files.
My second thought was to try to use webkit directly from C++ and use Python instead of Javascript, but that seems rather complicated, and I feel like overkilling by using Qt.
My third thought was to use a signed Java applet to make all local accesses, but then I'm not too sure of this either.
Any suggestions on what I should do?

I'll admit that I know very little about this, but it sounds like what you're after is what XUL provides.
From the homepage:
XUL (XML User Interface Language) is Mozilla's XML-based language that lets you build feature-rich cross platform applications that can run connected or disconnected from the Internet.
...
Web developers already familiar with Dynamic HTML (DHTML) will learn XUL quickly and can start building applications right away.
Regarding filesystem access: https://developer.mozilla.org/en/Code_snippets/File_I//O
This article describes local file input/output in chrome JavaScript.
You access the file system using Mozilla XPCOM components. A list of resources and interfaces for local I/O is available for both Files and Streams at XUL Planet.
Because of my lack of familiarity, I'll leave it up to the community to decide whether or not this answer has merit.
EDIT: Making this answer a community wiki since I don't have much real information to offer.

It seems, 5 years after the question was asked, there is a framework to do exactly this: build cross platform desktop app with JavaScript, HTML, and CSS, and with access to local files, http://electron.atom.io/.
I have not used it myself, but it is recommended in other answers.

You can always install needed servers locally and access user's local files that way.
I have been using Server2Go and MAMP

You could - for example - use Cappuccino: It allows you to build Applications in Objective-J (a language written in JavaScript) and run them either in the browser or as a Desktop application with local file access .
Then there is Adobe AIR, which allows you to write apps in JavaScript/HTML and access the file system.
Or you could use the new File Access API: http://hacks.mozilla.org/2009/12/w3c-fileapi-in-firefox-3-6/ (it has big restrictions, though: HTML 5 File API)
JavaScript is a beautiful language! Please update this question with information on which route you choose.

If you're not a Microsoft basher and/or don't mind being bound to IE, a Hypertext Terminal Application (HTA) is another option. I once (long ago) create a complete and pretty large stand alone database-application using HTA.

Do you know PHP? I suggest you to install Wamp or phpTriad or something similar for Windows. That way you can reach to the local files. If it is Linux most of the *nix based operating systems have build in Apache and PHP..

Mozilla currently develops Chromeless, which seems to be able to do exactly what you want and has filesystem access

Related

Is it possible to design GUI with HTML+CSS+JavaScript but it will actually run python script?

I've built a very simple assistant app in python which can do very basic tasks like taking notes, reminding you, stopwatch, timer, web scrape for news feeds etc. tkinter seems confusing and looks oldish to me. On the other hand, css js seems much easier to design gui side and way more elegant looking. Is it possible to design a desktop gui app (may be with electron?) using HTML+CSS+JavaScript but it will run my old python codes?
I've been coding for only two months and i suck at it. Please excuse my newbiness.
TLDR: Simply, i want to make the gui side using HTML+CSS+JavaScript to take user input but then it will run python scripts and shows output in the gui app. Is it possible?
It can't be done, you'd have to make it like a web app (although with local webserver serving python responses)
EDIT:
if you don't mind running it in webbrowser, you can make quite easily webserver, that will evaluate your queries...
The popular form of Javascript or ES6 (which you are talking about) is designed to run in browser, so, the limitations are that it can only make calls via browser, i.e. it cannot directly interact with the OS like python's OS module. This means you will need a web-service in your computer that would run a specific python code and return you the responses, this requires a web-service/web-framework, preferably python's like Django, Flask which will run the python script for you because they can make OS calls on the server machine. I do think other non-python web-services are cacpable to do so, but of course, the natural preference would be 'Python-based services'.
Sidenote:
If the case was with Node.js(i.e. the server-side js) and not ES6(client-side browser-run) you would have an upperhand i.e. you could invoke python scripts on your server because node.js like the python-based web-servers do support os calls.
Kinda, but its real ugly. If you can host your data and whatnot the other approaches will work.
You have to build your project around nw.js. Essentially it is a Chromium build that adds local file system access back in. You can build an HTML+JS Front end and access a node.js backend running in the same thread. Via node you can shellout to call your python program, or run a local python web server.
I built a mapping app that allowed the user to select a local file, process it on the local machine with python and display the results in an interactive D3 app with geojson based layers of the UnitedStates. Since the data was proprietary I could not host it outside the company. Since I was not IT, I could not host it inside the company. nw.js allowed me to package everything into an installer and deploy to other people within the company as a standalone app.
See here for more information:
Official site: http://nwjs.io
Official documentation: http://docs.nwjs.io/
Introduction
NW.js is an app runtime based on Chromium and node.js. You can write native apps in HTML and JavaScript with NW.js. It also lets you call Node.js modules directly from the DOM and enables a new way of writing native applications with all Web technologies.
It was created in the Intel Open Source Technology Center.
Features
Apps written in modern HTML5, CSS3, JS and WebGL.
Complete supportfor Node.js APIs and all its third party modules.
Good performance: Node and WebKit run in the same thread: Function
calls are made straightforward; objects are in the same heap and
can just reference each other;
Easy to package and distribute apps. Available on Linux, Mac OS X
and Windows

What are the other applications of javascript engine other than web browser

I was exploring javascript Engines and there types and came across this phrase (inside wiki article):
"Although there are several uses for a JavaScript engine, it is most commonly used in web browsers."
But above linked article has information and history related to its web browser application only. So, I searched a lot but could only able to find it's use in node.js for server side scripting. But, I am still curious to know if someone knows any other potential application of js-engine.
Thanks.
For, example, Node.js - JavaScript on a webserver.
Also there are solutions for different tasks, even AI and neuronetworks.
JavaScript is also commonly used for scripting.
For example you can use it in order to create routines for administration and data management in Mongo shell.
You can use JavaScript for advanced NGINX configuration scenarios.
Javascript can be used for game (Unity) and application development (UWP) etc

Is there an implementation of WebKit that allows accessing local filesystem easily?

I am creating a small app in HTML/CSS/JavaScript. Internet access is unavailable, and so it must run entirely offline. A researcher will be using the app to collect data, and a CSV file will be generated with this data for the research to analyze.
JS has built in security mechanisms to prevent access to the local file system. My current plan is to build a Chrome app, store everything in chrome.storage, and eventually write to a file using Chrome's chrome.fileSystem. This isn't ideal though, as it requires the researcher to grant access for every file (I'm not sure if you can grant access to folders?), or require the researcher to "download" files as opposed to having them simply be written to disk.
I am looking for a solution that would be as seamless as reading/writing to local files in other languages (Java, Python). I thought perhaps there may be a build of WebKit that allows this, or some chrome flags that I can set. Are there any better solutions?
nw.js (formerly node-webkit) appears to be what I was looking for.
It allows you to access node.js modules directly from the DOM, so you can write to local files using javascript inline with the rest of your code. It also allows you to package the app together so that you can deploy it as an executable.
It also appears to have an active community and numerous apps from developers, so it is production ready.
There is an upcoming API that could provide a seamless way to reading/writing to local files: Native File System API.
But currently only Chrome supports that (by a special flag).
WebKit is probably not the best starting point here - if you need access to the local filesystem and you feel as though you want to build the app in HTML & Javascript, you should look at Node.JS, which will allow you to use the familiar syntax but has the power to do all the backend file manipulation stuff you're looking for.
There are plenty of tutorials on Node.js, and with Express, you can be up and running quickly.

List local directory on Web Application

I have an idea a Web Application and I would need to list all files of a directory that exists on the client machine (For example C:\Temp).
I searched a lot on the Internet and as well on Stack Overflow. I couldn't find an answer on any questions that soved my problems.
I want to be able to list all files and subdirectories of a directory and if possible get the file type.
I know that this isn't able to do only with native Javascript. If there is something restricted to a browser like Firefox, like XPCOM I wouldn't mind using.
I just wanted to know what is the best approach to do this on a WEB Application. (Windows apps are not acceptable, and also don't want to rely on ActiveX since we're no planning on IE support).
We have a preference for Javascript based solutions. We really don't want to rely on Server-Side to do this. But we are opened to Server-Side suggestions.
For any server-side suggestion, we are using ASP .NET MVC.
We area looking for something similar to jscript - getting list of files in directory but I don't want to rely on ActiveX at all. As said before a Firefox-only solution would be OK.
In short:You can't get the control to list the files resides on local system(client machine) from browser.
Java applets, if signed and set up properly, can get access to the local filesystem if the user clicks allow on the popup dialog box.
Flash and Silverlight, being built by intelligent beings, do not allow you access to the local filesystem -- and if they did, they would also have a dialog pop up asking if the user trusts the web app. Otherwise people could use it to collect all sorts of potentially dangerous information about your system.

How to run JavaScript on the server

I'm writing an iPhone app that needs to interact with the Google Maps API, therefore I must user JavaScript (please correct me if I'm wrong) to access the results and the route created.
Since the JavaScript support in native iPhone apps is quite poor and slow, my idea was to ask a remote web server to do the job for me. That server would be running Apache and PHP.
So my question is, it possible to run JavaScript on the server side? And if possible, how would you do that?
Besides server-side Javascript, you could access Google Maps API from wrappers in other languages; for example, here is an open-source project that wraps the API for Python (it does so by generating and wrapping the needed Javascript) -- that may or may not help for your specific use case, of course (but similar issues apply to server-side JS).
After doing some research I found Aptana Jaxer, a open source software that allows you to run Ajax, HTML, JavaScript and DOM modification server-side. It's available in:
http://aptana.com/jaxer
In their website reads:
HTML, JavaScript, and CSS are all
native to Jaxer, as are
XMLHttpRequests, JSON, and DOM
scripting. And as a server it offers
access to databases, files, and
networking, as well as logging,
process management, scalability,
security, integration APIs, and
extensibility.
There's also a very nice screencast that will get you started in a minute: http://tv.aptana.com/videos/introduction-to-jaxer-10?ref=search&refId=jaxer
You can use javascript on a server, for a list of examples see this wikipedia article
Google Maps API v3 has support for iPhone web apps, and iPhone OS 3.0 has Google Maps support for native apps. Both are a bit bleeding-edge and not quite complete yet, as I write this.

Categories

Resources