0

Is there a way for me to get and set the values of JavaScript variables in a win form 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.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Drake
  • 3,851
  • 8
  • 39
  • 48
  • 5
    you should ask two questions in two questions. – Hamish Sep 16 '11 at 03:57
  • 1
    I believe the answer to your second question is "No". As far as I know you have to use `onmousemove` and store the coordinates yourself, possibly in conjunction with `onmouseout` to allow for when the user moves the mouse entirely out of the document. – nnnnnn Sep 16 '11 at 04:03

1 Answers1

0

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.

Community
  • 1
  • 1
VinayC
  • 47,395
  • 5
  • 59
  • 72