1

I'm trying to run a JavaScript function on a webpage from my C# codes.

This is the code from the website:

<div class="class34" onclick="sendpost(8);"></div><div class="class34" onclick="sendpost(9);"></div>
function sendpost(valg) {
    valget = {};
    valget.rane = valg
    poststuff('snas',valget, function(back) {
        $('#return').html(back.html);
    });
}

And this is the code I've tried to run it in C#:

webBrowser1.Document.InvokeScript("sendpost(8)");

and the result is that the code does nothing, I've been searching for the correct code to use but can't figure out what I'm doing wrong here.

How can I make my webBrowser1 either click or run the sendpost(8) function?

1 Answer 1

2

Documentation is you friend.

Go with:

Object[] args = new Object[1];
args[0] = 8;

webBrowser1.Document.InvokeScript("sendpost", args);

This will run the sendpost javascript method with the valg parameter/argument set to 8

Sign up to request clarification or add additional context in comments.

2 Comments

CS0103 The name 'newObject' does not exist in the current context
Sorry, typo ... should be new Object

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.