1

I am working on a project where I need to display a map with the user's current location on a Bing Maps (desktop application). I used an HTML document to get the coordinates and was able to display it in a WebBrowser control. Now I need access to the latitude and longitude values. I tried using Alex's approach in this question (his 2nd answer) but it only works if we are using web forms (WebBrowser.Document.GetElementbyId). Is there any way to get the values using the WebBrowser control in System.Windows.Controls namespace?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Raj123
  • 971
  • 2
  • 12
  • 24
  • Not sure if I correctly understand your question (as you haven't linked any other question and answer). But if it's just about parsing HTML in a .Net application, [Html Agility Pack](http://htmlagilitypack.codeplex.com/) may help a lot. – Clemens Sep 18 '13 at 07:41

1 Answers1

3

You can use WebBrowser.InvokeScript and eval to execute any JavaScript code inside the loaded page's namespace and get the result, e.g:

dynamic result = webBrowser.InvokeScript("eval", 
    new object[] { "{x: 0, y: 0, url: document.URL}" });
MessageBox.Show(result.url.ToString());
noseratio
  • 59,932
  • 34
  • 208
  • 486