[英]Catch an event fired on a website embedded in a winform
I have a web page that is embedded in my winform. 我有一个嵌入我的winform的网页。
When i click a button on my application the form shows up and navigates to a settings page. 当我单击应用程序上的按钮时,表单将显示并导航到设置页面。
What i want is to catch an event fired on the website. 我想要的是抓住网站上发生的事件。 eg if the user changes some settings on the webpage and clicks OK then i should catch that even and close my form automatically.
例如,如果用户更改了网页上的某些设置并单击“确定”,那么我应该自动捕获并自动关闭我的表单。
Is this even possible? 这甚至可能吗?
Here is the JS code for the OK click event 这是OK单击事件的JS代码
if (statusOK) {
Ext.Msg.show({
title : '',
buttons : Ext.Msg.OK,
msg : 'Default settings saved.',
icon : Ext.Msg.INFO
});
Any help will be appreciated. 任何帮助将不胜感激。
Thanks 谢谢
In your web page, you can do a redirect to some specialy crafted URL, like myapp://doStuff. 在您的网页中,您可以重定向到某个特制的URL,例如myapp:// doStuff。
And in the web browser control, you can subscribe to Navigating
event that will be fired when page tries to go to another URL. 在Web浏览器控件中,您可以订阅当页面尝试转到另一个URL时将触发的
Navigating
事件。 In that handler you can detect your specially crafted URLs and execute needed actions. 在该处理程序中,您可以检测特制URL并执行所需操作。
You can do the following in javascript 您可以在javascript中执行以下操作
window.external.MyFunction();
That will call the MyFunction() function in winforms. 这将在winforms中调用MyFunction()函数。
In your cs file you need: 在您的cs文件中,您需要:
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
before your class definition. 在你的课程定义之前。 And
MyFunction()
needs to be public. MyFunction()
需要公开。 In that function you can do to your form whatever you want. 在该功能中,无论您想要什么,您都可以使用您的表格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.