Home > Development, Visual Studio > C# Web Browser: Getting the value of a javascript property

C# Web Browser: Getting the value of a javascript property

Got asked a few times how to do this, and it seems this information is somehow not easily found on the internet.

 

If you are using the .NET Web Browser control, there IS a way to get the value of a javascript property/attribute/function etc etc.

 

Assuming I have a web browser control called WB, and I want to get the cookies for the page, what I need to do is basically call eval with the parameters I want

WB.Document.InvokeScript("eval", new object[] { "document.cookie" }).ToStringX()

 

in actual code

var myCookies = WB.Document.InvokeScript("eval", new object[] { "document.cookie" }).ToStringX();
MessageBox.Show(myCookies);

 

Hope this help you guys out there Smile

Categories: Development, Visual Studio
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: