How to call a jQuery function from .NET WebBrowser control using InvokeScript()?

前端 未结 3 499
予麋鹿
予麋鹿 2020-12-19 05:41

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 Javascri

3条回答
  •  温柔的废话
    2020-12-19 05:55

    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.

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

提交回复
热议问题