user2652125
user2652125

Reputation: 11

Run jQuery script in window application vb.net with in webrowser

There is a dropdown list in a HTML page:

I want to programmatically change the selected value from the dropdown list using:

webBrowser1.Document.InvokeScript

Executing

$('#year_sel').val('2012').change(); 

in FireBug console works but the same statement does not work when I use

webBrowser1.Document.InvokeScript("$('#year_sel').val('2012').change();")

How can I get that to work using InvokeScript?

Some help would be greatly appreciated.

Upvotes: 1

Views: 1994

Answers (2)

Nibbels
Nibbels

Reputation: 156

Here is a written out example which had been working for years:

Dim jsstrings As Object() = {"$('#year_sel').val('2012').change();"}
WebBrowser.Document.InvokeScript("eval", codestring)

It is using javascripts eval plus a parameter.

Upvotes: 1

noseratio
noseratio

Reputation: 61686

WebBrowser.Document.InvokeScript expects a JavaScript function name, rather than a script fragment. The function has to be already available in the page's global JavaScript namespace. You can do what you're after by using JavaScript's eval, here is how.

Upvotes: 0

Related Questions