WebBrowser控件和Javascript [英] WebBrowser Control and Javascript

查看:93
本文介绍了WebBrowser控件和Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在应用程序中为其用户界面使用WebBrowser控件.到目前为止,我一直在使用链接(#something)和WebBrowser的Navigating事件,以便应用程序知道用户单击链接时的操作,但是我看到一些嵌入了WebBrowser控件并使用javascript进行通话的应用程序与应用程序一起使用(链接可见,它类似于javascript:"some_function();").
我的问题是我应该如何创建自定义javascript函数,以映射到应用程序内部的函数(使用c#,类似于该应用程序的javascript API.)
感谢您的帮助:)

Hello, I am using the WebBrowser control in an application for it''s user interface. So far I have been using links (#something) and the Navigating event of the WebBrowser so that the app knows what to do when the user clicks a link, however I have seen some applications that has the WebBrowser control embedded and use javascript to talk with the app (the link is visible, it''s something like javascript:"some_function();").
My question is how to should I create custom javascript functions that map to functions from inside the app (built with c#, something like a javascript API for the app).
Thanks for your help :)

推荐答案

WebBrowser控件具有一个名为ObjectForScripting的属性.您可以将其分配给其类标记为Com Visible的任何对象.
该对象将以window.external的形式显示在javascript代码中.您可以调用原始对象公开的任何方法.

有关参考和示例,请参见:
WebBrowser Control has a property named ObjectForScripting. You can assign it to any object whose class is marked as Com Visible.
That object will be exposed to javascript code as window.external. You can call any method exposed by the original object.

For reference and examples, look here: System.Windows.Forms.WebBrowser.ObjectForScripting[^]


这篇关于WebBrowser控件和Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆