简体   繁体   English

如何将消息(字符串)从Win32应用程序发送到在现有IE窗口中运行的Javascript程序?

[英]How might I send messages (strings) from a Win32 app to a Javascript program running in an existing IE window?

I have a system tray icon that receives incoming phone calls. 我有一个系统托盘图标,可以接听来电。 When a call comes in, I want to send the phone number into a web app that does stuff on that phone number. 当有电话打进来时,我想将电话号码发送到在该电话号码上进行填充的Web应用程序中。 We can launch the web app with the phone number in a query string, but if I launch a new window for every call, it will junk up the user's computer with lots of browser instances, would not preserve the location/size the user moved the browser window to, and would take longer than just refreshing the page. 我们可以使用查询字符串中的电话号码来启动Web应用程序,但是如果我为每个呼叫启动一个新窗口,它将用大量浏览器实例将用户的计算机浪费掉,而不会保留用户将其移动到的位置/大小。浏览器窗口,并且刷新页面所花的时间会更长。 Instead, I'd like to make the Win32 app re-use the same IE browser window and just send the web app the new phone number every time a new call comes in. I'm envisioning somehow sending a Windows message, or somehow instructing the IE browser to run a certain javascript event with some data? 相反,我想让Win32应用程序重新使用相同的IE浏览器窗口,并在每次接到新电话时仅向Web应用程序发送新的电话号码。我正在设想以某种方式发送Windows消息或以某种方式指示IE浏览器以某些数据运行某个javascript事件? I can see why doing the reverse (javascript out to Win32) would be a security issue, but this would be just sending a message from Win32 to javascript. 我可以看到为什么进行反向操作(将JavaScript输出到Win32)是一个安全问题,但这只是从Win32向javascript发送消息。

So I'm specifically NOT asking how to do what's been answered in this question: How to Interact Between Web App and Windows Form Application 因此,我并不是要问这个问题该如何回答: 如何在Web App和Windows Form Application之间进行交互

That user was asking how to launch a Win32 app from Javascript and pass data to the win32 app. 该用户正在询问如何从Javascript启动Win32应用程序并将数据传递给Win32应用程序。 Roughly, I need to do the opposite. 大致上,我需要做相反的事情。 I need to send data from a Win32 app into a running javascript program. 我需要将数据从Win32应用程序发送到正在运行的javascript程序中。

Note also that I'm not asking how to launch one IE window with arguments to Javascript one time; 还要注意,我并不是在问如何一次启动一个带有Javascript参数的IE窗口。 I can easily do that with query strings. 我可以使用查询字符串轻松做到这一点。 What I'm asking is how can I / is it possible to pass data from a running Win32 app outside the browser to a running Javascript app inside a browser window. 我要问的是如何/如何将数据从浏览器外部正在运行的Win32应用程序传递到浏览器窗口内正在运行的Javascript应用程序。

You should be able to find the handle of the IE window, and then send messages (keypresses perhaps) to it. 您应该能够找到IE窗口的句柄,然后向其发送消息(也许是按键)。 Use a bit of javascript to capture all keypress activity and you have a very simple method to transfer information. 使用少量的JavaScript捕获所有按键活动,您就有一种非常简单的方法来传输信息。

It won't be easy (the devil is in the details - issues of focus, etc) but it should be possible. 这并非易事(细节在于魔鬼-焦点问题等),但应该可以。

-Adam -亚当

Since you can send the phone number to the site through a querystring, all you really need to do is tell IE to navigate to a URL of your choosing. 由于您可以通过查询字符串将电话号码发送到站点,因此您真正需要做的就是告诉IE导航到您选择的URL。

To that end, you can use what is in this KB article to help you find the instance of IE you want to connect to. 为此,您可以使用此知识库文章中的内容来帮助您找到要连接的IE实例。

http://support.microsoft.com/kb/299356/de http://support.microsoft.com/kb/299356/de

Granted, its in Visual J++ of all things, but since you are interacting through COM Automation, the calls should be easy to translate. 当然,它在Visual J ++中是所有事物,但是由于您是通过COM Automation进行交互的,因此调用应该易于翻译。

Once you have the instance of IE (in the form of an IWebBrowser2 interface implementation) you can simply call the Navigate or Navigate2 method with the URL you need (with the phone number in the query string of course). 拥有IE实例(以IWebBrowser2接口实现的形式)后,您只需使用所需的URL(当然,在查询字符串中包含电话号码)即可调用Navigate或Navigate2方法。

What you need is a way to How To Connect to a Running Instance of Internet Explorer (caveat: this one is in Java, but you should be able to translate it to C# quite easy). 您需要的是一种如何连接到Internet Explorer正在运行的实例的方法 (注意:这是用Java编写的,但是您应该可以很容易地将其转换为C#)。

Or you could enumerate the top-level windows to find a particular instance of IE and then Get IHTMLDocument2 from a HWND (this one is in C++, so you might need to do some Win32 interop; you can find all necessary declarations on PInvoke.net ). 或者,您可以枚举顶级窗口以查找IE的特定实例,然后从HWND获取IHTMLDocument2 (此实例在C ++中,因此您可能需要进行一些Win32互操作;您可以在PInvoke.net上找到所有必要的声明。 )。

If you search on your friendly local search engine for How to connect to a running instance of Internet Explorer , you will find a lot more info. 如果您在友好的本地搜索引擎上搜索“ 如何连接到Internet Explorer的运行实例” ,则会发现更多信息。

Once you get to the document, you can either invoke the JavaScript function through the document scripting interface, or you can just navigate it to your page and pass the phone number as a parameter. 进入文档后,您可以通过文档脚本界面调用JavaScript函数,也可以仅将其导航到页面并将电话号码作为参数传递。

you could possibly get around the security and other issues with this method by using a web service on the web server, and have the win32 app update the web service and have the web page poll the same web service every however many seconds. 您可以通过在Web服务器上使用Web服务来解决此方法的安全性和其他问题,并让win32应用程序更新Web服务并使网页每隔几秒钟轮询一次相同的Web服务。 Then you the the option of mapping that number to a database and getting additional information. 然后,您可以选择将该号码映射到数据库并获取其他信息。

The only draw back is that instead of being immediate, there is a delay to get the information displayed in the browser. 唯一的缺点是,要立即在浏览器中显示信息,需要立即延迟,而不是立即进行。

How about you write an active-x control that you create in the browser using Javascript. 如何编写使用Javascript在浏览器中创建的active-x控件。 This is effectively an Explorer browser plugin. 这实际上是一个Explorer浏览器插件。 Same idea for Mozilla, etc., except they use a different plug-in structure. Mozilla等的想法相同,只是它们使用不同的插件结构。 This lets you support other browsers in the future. 这使您将来可以支持其他浏览器。

The control can talk to your win32 app using a pipe or a socket or whatever type of inter-process communications and is then accessible as a Javascript object. 该控件可以使用管道或套接字或任何类型的进程间通信与您的win32应用程序对话,然后可以作为Javascript对象进行访问。

暂无
暂无

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

相关问题 UWP JavaScript APP:带参数运行win32 EXE - UWP JavaScript APP: run win32 EXE with parameters 如何在PHP / JavaScript中实现Win32函数MessageBox的等效功能? - How to implement the equivalent of the Win32 function MessageBox in PHP/JavaScript? C ++,win32 api:如何创建一个html渲染窗口,以便你的应用程序从JS调用中获得回调? - C++, win32 api: How to create an html rendering window so that your application would get callbacks from JS calls? 如何使用 ActiveMQ-Artemis 从 Java 程序向 Javascript STOMP 客户端发送消息? - How do I send messages from Java program to a Javascript STOMP client using ActiveMQ-Artemis? JavaScript ActiveXObject-如何运行win32应用程序并等待其终止,然后再进行下一步? - JavaScript ActiveXObject - How to run win32 apps and wait for their termination before next step? Javascript window.open在Win7 x64上的32位IE8中返回null - Javascript window.open returns null in 32-bit IE8 on Win7 x64 如何将消息从Javascript发送到Java? - How do I send messages from Javascript to Java? OpenLayers 3 Rotation示例在Win32触摸设备上的IE / Chrome嵌入式WebBrowser控件中的行为有所不同 - OpenLayers 3 Rotation example behaves differently in IE/Chrome embedded WebBrowser control on Win32 touch device 为什么window.navigator.platform 在64 位机器上返回WIN32? - Why does window.navigator.platform return WIN32 on a 64-bit machine? 在Google Chrome浏览器中,如何使用父窗口中的javascript将现有的弹出窗口置于最前面? - In Google Chrome, how do I bring an existing popup window to the front using javascript from the parent window?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM