开发者

web browser set javascript variable value

Is there a way for me to get and set the values of JavaScript variables in a win f开发者_如何转开发orm web browser so it can communicate with my application. The only way I can think of accomplishing this is by using a proxy of an invisible element such as a div that will have an attribute or inner HTML set to the value I want to read/write.

Also, is there a JavaScript function that gets me the cursor's current position. Not event based callsbacks that have the position in its parameters. This is for a complicated application.


One of the simplest way is to inject script element into the document containing necessary java-script. See this SO question for how to do that: How to inject Javascript in WebBrowser control?

Another (recommended) way is to use WebBrowser.ObjectForScripting that can be used to communicate between your application and java-script within web browser. You also need to use browserControl.Document.InvokeScript method to trigger the java-script functions. InvokeScript can also be used instead of script injection method.

For second question, AFAIK, cursor position has to be tracked using mouse events.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜