如何使用InvokeScript()从.NET WebBrowser控件调用jQuery函数? [英] How to call a jQuery function from .NET WebBrowser control using InvokeScript()?

查看:136
本文介绍了如何使用InvokeScript()从.NET WebBrowser控件调用jQuery函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

拥有一个使用WebBrowser控件(.NET 4)的Windows Forms应用程序,以加载与该应用程序通信的网页.我有一次调用InvokeScript()来一次在网页中调用Javascript例程.

Had a Windows Forms app using a WebBrowser control (.NET 4) to load a web page that communicated with the app. I had a call to InvokeScript() to call a Javascript routine in the web page at one point.

现在事情已经更新"了,现在正在使用jQuery.因此,现在不再需要调用OnVenueSelected()函数,而是有些$.city.venue.onVenueSelected: function(param)奇怪之处.

Now things have been "updated", and jQuery is now being used. So instead of having a OnVenueSelected() function to call, it's now some $.city.venue.onVenueSelected: function(param) oddity.

仅将我的通话从InvokeScript("OnVenueSelected", new object[] { params })更改为InvokeScript("$.city.venue.onVenueSelected", new object[] { params })无效.我没有看到任何可观察到的错误或异常,但是未调用调用中的逻辑.

Simply changing my call from InvokeScript("OnVenueSelected", new object[] { params }) to InvokeScript("$.city.venue.onVenueSelected", new object[] { params }) did not work. I don't get any observable errors or exceptions, but the logic in the call is not invoked.

有些研究让我尝试使用eval作为调用并将函数名称和参数作为字符串传递给eval.那也不起作用.

Some digging around had me trying to use eval as the call and passing the function name and parameters as the string to eval. That didn't work either.

是否存在一种已知的方法来调用嵌入在jQuery魔术层中的函数?

Is there a known way to invoke a function that's embedded in a couple of layers of jQuery magic?

谢谢.

推荐答案

好-我要回答我自己的问题.部分感谢的回答如何使用InvokeScript()从.NET WebBrowser控件中调用jQuery函数?,我能够将对jQuery函数的调用更改为

OK - I get to answer my own question. Thanks in part to the answer by at How to call a jQuery function from .NET WebBrowser control using InvokeScript()?, I was able to change my call to the jQuery function to

string[] codeString = { String.Format(" {0}('{1}') ", @"$.city.venue.onVenueSelected", result.ToString()) };
this.myBrowser.Document.InvokeScript("eval", codeString);

令人惊讶的是,这似乎正在起作用.

Amazingly enough, this seems to be working.

就我而言,结果变量的类型为bool(如果对任何人都重要).

In my case, the result variable is of type bool (in case that matters to anyone).

这篇关于如何使用InvokeScript()从.NET WebBrowser控件调用jQuery函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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