【发布时间】:2016-12-02 14:47:41
【问题描述】:
我在我的VB.NET(Windows 窗体应用程序)程序中使用GeckoWebBrowser。 GeckoWebBrowser 加载本地 html 文件。这个html 嵌入了一个svg 文件(human body diagram with bones and internal organs)和一个javascript 函数,用于从svg 文档中获取元素的所有“id”。我想从VB.NET(Windows 窗体应用程序)调用上述javascript 函数,但我不知道该怎么做。任何人都可以帮助我,或者给我一个源代码示例吗?我找到的所有东西都基于C#...
这是我的javascript 文件中的javascript 函数:
<script type="text/javascript">
(funcion () {
// Function to be called in VB.NET when the DOM is loaded
var SVGHandler = function () {
// Picking up the id Root Node="CUERPO_HUMANO" into svg variable
var svg = document.querySelector('#CUERPO_HUMANO');
// In Items we save all the <g> which have an ID
var items = svg.querySelectorAll('g[id], path[id]');
//var items = svg.querySelectorAll('g[id]');
// We loop all the nodes saved in Items and add them to click event listener
forEach(items, function (index, value) {
value.addEventListener('click', function (event) {
event.preventDefault();
//We avoid the spread of events
event.stopPropagation();
return event.currentTarget.id
// console.log(event.currentTarget.id)
});
});
}
// https://toddmotto.com/ditch-the-array-foreach-call-nodelist-hack/
var forEach = function (array, callback, scope) {
for (var i = 0; i < array.length; i++) {
callback.call(scope, i, array[i]); // passes back stuff we need
}
};
// With this method, we call a SVGHandler when DOM is totally loaded
document.addEventListener('DOMContentLoaded', SVGHandler);
})();
</script>
每次单击GeckoWebBrowser 中加载的人体图中的特定骨骼或器官时,我应该在VB.NET 中使用什么代码来调用我的javascript 函数?
我想将调用时获取的“id”保存到string 变量中,以便将其用作SQL 语句中的参数并填充DataGridView。
我一直在搜索,我能找到的所有内容都与 C# 相关,而不是单个 VB.NET 示例。尽管我试图找出VB.NET 中的等价性,试图将C# 的示例转换为VB.NET,但我对如何进行javascript 调用仍有一些疑问。根据我的javascript 函数可能是这样的:
browserControl.Navigate("javascript:void(funcion())");
请问,谁能帮我解决这个问题?我会非常感谢...
【问题讨论】:
标签: javascript vb.net web browser gecko