是否可以编写一个不需要服务器的本地Web应用程序?
我想创建一个本地应用程序,它具有基于浏览器的 UI,而不是基于 MFC / Qt / 等的独立 GUI。如果我不想在本地计算机上运行 Web 服务器,如何实现动态我的应用程序的一部分?浏览器可以指向机器上的本地脚本、可执行文件或库吗?可以直接使用本地数据库吗>这种方法有什么陷阱?
I want to create a local application that has a browser-based UI rather than a stand-alone GUI based on MFC / Qt / etc. If I don't want to run a webserver on the local machine, how can I implement the dynamic parts of my app? Can the browser be pointed to local scripts, executables or libraries on the machine? Can I use a local database directly> What pitfalls are there with this approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,但有限制。主要限制是您无法执行任何 CGI 操作,因为浏览器将打开并显示您的脚本源代码而不是执行它们。这有几个含义:
但也有解决方法。 HTML5 允许您将数据存储在本地存储中,但显然这在旧版浏览器中不起作用。您可以将数据存储在 cookie 中,但这有大小限制。最后你可以实际保存到文件。您必须指示您的用户修改他们的浏览器首选项,以允许您的脚本执行此操作,但这是可以完成的。 TiddlyWiki 就是一个例子。它是一个独立的个人 wiki,位于单个 HTML 文件中。每次保存新内容时,页面都会修改并保存自身。您可能想看看他们是如何做到的以获得灵感。
Yes it is, but with limitations. The main limitation is that you can't do any CGI stuff because the browser will open and display your script source code instead of executing them. This has several implications:
But there are workarounds. HTML5 allows you to store data in local storage but obviously this won't work in older browsers. You can store data in cookies instead but that has size limitations. Finally you can actually save to file. You have to instruct your users to modify their browser preferences to allow your script to do this but it can be done. One example of this is TiddlyWiki. It is a self-contained personal wiki in a single HTML file. Every time you save new content the page modifies and saves itself. You may want to look at how they do it for inspiration.
我相信在这种情况下,你唯一的脚本选择就是 Javascript。 (或者 Java Applets 或 Flash,但我不认为你想要那样)
我建议看看 QT 的嵌入式 webkit。您可以使用它将浏览器嵌入到简单的 QT 应用程序中,并将其用于大部分 UI,然后您的后端就可以使用 C++/QT 的强大功能。 QT 能够将 C++ 代码直接链接到 Javascript。
请参阅 QWebFrame 类,尤其是 addToJavaScriptWindowObject 方法,以及 Qt WebKit 桥。
I believe your only options in terms of scripting would be Javascript in this scenario. (Or Java Applets or Flash, but I don't think you want that)
I would suggest taking a look at QT's embedded webkit. You could use that to embed a browser in a simple QT app and use that for most of your UI, then you have the power of C++/QT for your backend. QT is able to link C++ code directly to Javascript.
See the QWebFrame class, especially the addToJavaScriptWindowObject method, and the Qt WebKit Bridge.
如果你想要纯HTML路线,HTML5会让你在浏览器中创建一个本地数据库;如果有足够的 JavaScript 编码经验,您可以在其中编写整个网站,用 JS 呈现所有内容,而不是加载 HTML 文件。加载一个文件并使用 javascript 引擎渲染此后的所有内容。
如果它是一个有意义的应用程序,并且您可以这样编写它,而不会发疯,向您致敬。
如果您使用的是 Windows,您可以作弊并使用 Active x/ vbscript - 但如果您这样做,为什么不编写一个单击一次 .net 应用程序。如果没有某些 Web 服务器应用程序组件,浏览器将无法与传统数据库引擎通信。
If you want the pure HTML route HTML5 will let you create a local database in the browser; with enough javascript coding experience you could write an entire site in it that renders everything in JS rather than loading HTML files. Loads one file and renders everything after that using the javascript engine.
If its a meaningful app and you can write it that way without going mad salute you.
If you are on windows you could cheat and use Active x/ vbscript - but if you are doing that why not write a click once .net application. Without having some web server application component the browser won't be able to talk to a traditional database engine.