Is it possible to write a local web application that does not need a server?

I want to create a local application with a browser based user interface and not a standalone graphical interface based on MFC / Qt / etc. If I do not want to run the web server on the local machine, how can I implement the dynamic parts of my application? Is it possible to point the browser to local scripts, executable files, or libraries on the computer? Can I directly use the local database> What are the pitfalls with this approach?

+6
source share
3 answers

Yes, but with limitations. The main limitation is that you cannot make any CGI materials because the browser will open and display the source code of the script instead of executing them. This has several consequences:

  • You cannot connect to the database. This makes it difficult to do common things, such as storing states and user data.
  • You cannot set Content-type. This means that you cannot make any fancy XML materials, such as serving SVG files or using XML in XMLHttpRequest.
  • You cannot create dynamic images (with ImageMagick or GD). Although with HTML5 you can do this with a canvas.
  • You cannot read or write to the file system. Again, this limits your ability to save data. But this can be done using the correct user rights (more on this below).

But there are workarounds. HTML5 allows you to store data in local storage, but obviously this will not work in older browsers. Instead, you can store data in cookies, but with size restrictions. Finally, you can save the file. You must tell your users to change their browser settings for your script to do this, but you can do it. One example of this is TiddlyWiki . This is a standalone personal wiki in one HTML file. Each time you save new content, the page changes and saves itself. You can see how they do it for inspiration.

+4
source

I believe that your only options in the scripts will be Javascript in this script. (Either Java applets or Flash, but I don't think you want it)

I would suggest taking a look at the built-in webkit QT. You can use this to embed a browser in a simple QT application and use it for most of your user interface, then you have the C ++ / QT power for your backend. QT can associate C ++ code directly with Javascript.

See the QWebFrame class , especially addToJavaScriptWindowObject and Qt WebKit Bridge .

+2
source

If you want a clean HTML5 HTML route, you can create a local database in the browser; with enough javascript coding experience, you could write a whole site in it that displays everything in JS rather than loading HTML files. Loads a single file and does everything after it using the javascript engine.

If this is a meaningful application, and you can write it this way without losing your mind, welcome you.

If you are on Windows, you can cheat and use Active x / vbscript, but if you do this, why not write a one-time .net application. Without the presence of any component of the web server application, the browser will not be able to talk with the traditional database engine.

+1
source

Source: https://habr.com/ru/post/903060/


All Articles