简体   繁体   English

c#WebBrowser调用Javascript

[英]c# WebBrowser invoke Javascript

Hello im trying to run a javascript function on a webpage from my c# codes.您好,我正在尝试从我的 C# 代码在网页上运行 javascript 函数。

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 ive tried to run it in c#这是我试图在 c# 中运行它的代码

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

and the result is that the code does nothing, ive been searching for the correct code to use but cant figure out what im doing wrong here.结果是代码什么都不做,我一直在寻找要使用的正确代码,但无法弄清楚我在这里做错了什么。

i need help understanding how to make my webBrowser1 either click or run the sendpost(8) function我需要帮助了解如何让我的 webBrowser1 单击或运行 sendpost(8) 函数

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这将运行valg参数/参数设置为 8 的sendpost javascript 方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM