Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building a Windows app w/ embedded browser & JavaScript 'hooks'

I built a PHP / JavaScript website for a customer. Then they asked me to replicate it except as a standalone Mac application. I did this with an app that combined an embedded web server, PHP, and 'WebView' - a Cocoa-ish version of the WebKit web browser that I can embed in a standard app window. This all worked great - I got to reuse 10,000+ lines of PHP/JS code, which saved months off of re-implementing it all again in 'native' code.

Now they want a Windows equivalent. I'm reasonably confident I can get PHP and the web server to work. And I know embedding basic IE functionality is pretty easy.

However...in my Mac setup, WebView (via the windowScriptObject stuff) gave me the ability to call JavaScript methods from C++. For instance, I might call a JavaScript method from C++ to update the screen. Likewise I could set things up so that a JavaScript call in the browser could trigger a C++ method - I used this, for instance, to let a user click 'BROWSE' and pick a file path using a real, standard file browser.

So my question is, is there a Windows-based embedded browser setup that would let me interact with JavaScript in this same way?

(the JavaScript <--> WebKit interface is described in much better detail here: http://lipidity.com/apple/javascript-cocoa-webkit/)

like image 207
Matt Walsh Avatar asked Mar 03 '11 03:03

Matt Walsh


People also ask

Can you make a desktop application run in a browser?

Navigate to the server's URL with your browser of choice. Log in to the server using credentials configured on the server. Click on the Run in browser button under the desired application. A browser window will open, containing the application.

What is Windows WebView?

The WebView control shows web content in your Windows Forms or WPF desktop application. This is one of several wrapped Universal Windows Platform controls that are available for Windows Forms and WPF applications.

How do I convert a web app to a desktop app using chromium?

Open Chromium Edge and head to the site you want to use as an app. Then click the Settings button (three dots in the upper-right corner) and go to Apps > Install. Next, type in a meaningful name for the shortcut of the web app and click the Install button. That's it.


3 Answers

Maybe try using something like Appcelerator Titanium so you'll be ready when your client says they want it to work on Linux, or iPhone, or Android.

Quoting Wikipedia: "Appcelerator Titanium is a platform for developing mobile and desktop applications using web technologies. [...] Support for standards-based web technologies: HTML, CSS and Javascript on all platforms along with PHP, Python and Ruby for desktop platforms. Integrated support for popular JavaScript and AJAX Frameworks including jQuery, YUI, MooTools, Scriptaculous and others."

Sounds like a perfect tool for the job.

like image 160
rsp Avatar answered Sep 30 '22 00:09

rsp


When you embed the Web Browser Control (IE), your application code can simply call execScript (http://msdn.microsoft.com/en-us/library/ms536420(v=vs.85).aspx) on the window object. You can have your script call out to the application by using the window.external object from the script, and by using the ObjectForScripting (or C++ equivalent) from the application.

like image 44
EricLaw Avatar answered Sep 30 '22 00:09

EricLaw


maybe Qt will be good for your case, also you have QtScript and can inject javascript with evaluateJavaScript

like image 44
fazo Avatar answered Sep 29 '22 22:09

fazo