简体   繁体   中英

Communication between javascript and its hosting java or c++ application

I'm trying to find out if there is a standard or recommended way to communicate from javascript to the application which embeds a browser widget, and vice versa. The hosting application may be written in either java or c++ and may run on Windows and Unix platforms, but the javascript would be shared across both clients.

So far I've read about:

  • window.external (This seems to be IE specific, so it wouldn't work on Unix.)
  • LiveConnect (This seems to be java and mozilla specific, so it wouldn't work for IE or c++ based applications.)
  • SWT's Browser widget has some of this capability, but this would be a java-only solution..

What other options are out there?

Thanks! Shyam

We have a VB6 application that hosts Microsoft's WebBrowser object (IE). We've used a simple URL intercept mechanism to facilitate communication between the browser and the hosting application. Since the browser control has a before navigate interface, we can pull out the URL and examine it for commands and either cancel the navigation event (since it was meant for the hosting app) or let it pass through (since it is a normal URL).

We used something like app://commandName?arg1=val&arg2=val in our Javascript or HTML link tags.

Then in the BeforeNavigate event from the browser, we check the url for app:// if we get that, we know the browser is sending the parent application a message.

Simple but effective (for our needs anyway).

EDIT

Should also mention that most embedded browsers also have mechanisms to manipulate the DOM. That in mind you should be able to extract information (HTML nodes) and inject information at will.

JavaScript has the XMLHttpRequest API that makes it possible to send data to, and retrieve data from a server. The use of this API with messages formatted in XML or JSON is designated AJAX .

AJAX can be used to implement the example you gave, of a tree node in the HTML/javascript that retrieves the list of children from the server when it is expanded. Note that when using AJAX, the server may be written in any language (C, Java, Python, Ruby, etc).

I suggest you to read about AJAX. After you get a good understanding of AJAX you can read a little bit about web services . web service is a method of communication of 2 applications developed in arbitrary programming languages through the WEB.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM