简体   繁体   English

javascript与其托管java或c++应用程序之间的通信

[英]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.我试图找出是否有标准或推荐的方式从 javascript 到嵌入浏览器小部件的应用程序进行通信,反之亦然。 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.托管应用程序可以用 java 或 c++ 编写,并可以在 Windows 和 Unix 平台上运行,但 javascript 将在两个客户端之间共享。

So far I've read about:到目前为止,我已经读到:

  • window.external (This seems to be IE specific, so it wouldn't work on Unix.) window.external(这似乎是 IE 特定的,因此它不适用于 Unix。)
  • LiveConnect (This seems to be java and mozilla specific, so it wouldn't work for IE or c++ based applications.) LiveConnect(这似乎是 java 和 mozilla 特定的,因此它不适用于基于 IE 或 c++ 的应用程序。)
  • SWT's Browser widget has some of this capability, but this would be a java-only solution.. SWT 的浏览器小部件具有部分这种功能,但这将是一个仅限 Java 的解决方案。

What other options are out there?还有哪些其他选择?

Thanks!谢谢! Shyam夏姆

We have a VB6 application that hosts Microsoft's WebBrowser object (IE).我们有一个 VB6 应用程序托管 Microsoft 的WebBrowser object (IE)。 We've used a simple URL intercept mechanism to facilitate communication between the browser and the hosting application.我们使用了一个简单的 URL 拦截机制来促进浏览器和托管应用程序之间的通信。 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).由于浏览器控件有一个之前的导航界面,我们可以拉出 URL 并检查它的命令,然后取消导航事件(因为它是针对托管应用程序的)或让它通过(因为它是一个普通的 URL) .

We used something like app://commandName?arg1=val&arg2=val in our Javascript or HTML link tags.我们在 Javascript 或 HTML 链接标签中使用了类似app://commandName?arg1=val&arg2=val的内容。

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.然后在浏览器的 BeforeNavigate 事件中,我们检查 url 中的app://如果我们得到它,我们就知道浏览器正在向父应用程序发送消息。

Simple but effective (for our needs anyway).简单但有效(无论如何满足我们的需要)。

EDIT编辑

Should also mention that most embedded browsers also have mechanisms to manipulate the DOM.还应该提到的是,大多数嵌入式浏览器也有操作 DOM 的机制。 That in mind you should be able to extract information (HTML nodes) and inject information at will.请记住,您应该能够随意提取信息(HTML 节点)和注入信息。

JavaScript has the XMLHttpRequest API that makes it possible to send data to, and retrieve data from a server. JavaScript 有XMLHttpRequest API,这使得向服务器发送数据和从服务器检索数据成为可能。 The use of this API with messages formatted in XML or JSON is designated AJAX .将此 API 与格式为 XML 或 JSON 的消息一起使用被指定为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. AJAX 可用于实现您给出的示例,HTML/javascript 中的树节点在扩展时从服务器检索子节点列表。 Note that when using AJAX, the server may be written in any language (C, Java, Python, Ruby, etc).请注意,使用 AJAX 时,服务器可以用任何语言编写(C、Java、Python、Ruby 等)。

I suggest you to read about AJAX. After you get a good understanding of AJAX you can read a little bit about web services .我建议你看一下AJAX。在你对AJAX有了很好的了解之后,你可以稍微了解一下web的服务 web service is a method of communication of 2 applications developed in arbitrary programming languages through the WEB. web 服务是通过 WEB 以任意编程语言开发的 2 个应用程序的通信方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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