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

时间:2022-09-01 19:20:34

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.

我试图找出是否有标准或推荐的方式从javascript通信到嵌入浏览器小部件的应用程序,反之亦然。托管应用程序可以用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

2 个解决方案

#1


0  

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).

我们有一个VB6应用程序,它承载Microsoft的WebBrowser对象(IE)。我们使用了一种简单的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事件中,我们检查app://的url如果我们得到了,我们知道浏览器正在向父应用程序发送消息。

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.

还应该提到的是,大多数嵌入式浏览器还具有操纵DOM的机制。请记住,您应该能够提取信息(HTML节点)并随意注入信息。

#2


0  

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.

JavaScript具有XMLHttpRequest API,可以将数据发送到服务器并从服务器检索数据。将此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. Note that when using AJAX, the server may be written in any language (C, Java, Python, Ruby, etc).

AJAX可用于实现您给出的示例,HTML / javascript中的树节点在扩展时从服务器检索子节点列表。请注意,使用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. web service is a method of communication of 2 applications developed in arbitrary programming languages through the WEB.

我建议你阅读有关AJAX的内容。在熟悉了AJAX之后,您可以阅读一些有关Web服务的内容。 Web服务是通过WEB以任意编程语言开发的2个应用程序的通信方法。

#1


0  

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).

我们有一个VB6应用程序,它承载Microsoft的WebBrowser对象(IE)。我们使用了一种简单的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事件中,我们检查app://的url如果我们得到了,我们知道浏览器正在向父应用程序发送消息。

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.

还应该提到的是,大多数嵌入式浏览器还具有操纵DOM的机制。请记住,您应该能够提取信息(HTML节点)并随意注入信息。

#2


0  

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.

JavaScript具有XMLHttpRequest API,可以将数据发送到服务器并从服务器检索数据。将此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. Note that when using AJAX, the server may be written in any language (C, Java, Python, Ruby, etc).

AJAX可用于实现您给出的示例,HTML / javascript中的树节点在扩展时从服务器检索子节点列表。请注意,使用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. web service is a method of communication of 2 applications developed in arbitrary programming languages through the WEB.

我建议你阅读有关AJAX的内容。在熟悉了AJAX之后,您可以阅读一些有关Web服务的内容。 Web服务是通过WEB以任意编程语言开发的2个应用程序的通信方法。