我想在C#中调用onclick。我把WebBrowser放到基于C#的程序中,在网站上,有一个按钮与js
函数绑定
type="button"
onclick="submitEdgeStory();"
value="Invia la news" class="submit"
我想调用onclick
方法。我试着用submitEdgeStory
打电话:
webBrowser1.Document.InvokeScript("submitEdgeStory()");
或
webBrowser1.Document.Forms[1]
.SetAttribute("onclick", "return submitEdgeStory()");
但没办法..我不知道怎么称呼这个功能......
PS:我没有使用ASP.NET
。它只是一个桌面应用程序
这也是js功能
var gPageIsOkToExit = false;
function submitEdgeStory()
{
// Set a variable so that our "before unload" exit handler knows not to verify
// the page exit operation.
gPageIsOkToExit = true;
// Do the submission.
// var frm = document.getElementById("thisform");
frms = document.getElementsByName("ATISUBMIT");
if (frms)
{
if (frms[0])
frms[0].submit();
}
}
window.onbeforeunload = function (event)
{
// See if this is a safe exit.
if (gPageIsOkToExit)
return;
if (!event && window.event)
event = window.event;
event.returnValue = "You have not hit the Submit Button to submit your story yet.";
}
答案 0 :(得分:1)
如果您为按钮分配了ID
type="button"
onclick="submitEdgeStory();"
value="Invia la news" class="submit" id="buttonid"
然后你可以做 -
WebBrowser1.Document.GetElementById("buttonid").InvokeMember("submit")
答案 1 :(得分:1)
我就这样解决了
foreach (HtmlElement item in webBrowser1.Document.All)
{
if ( item.OuterHtml != null)
{
if (item.OuterHtml.Contains("submitEdgeStory"))
{
item.InvokeMember("click");
break;
}
}
}
答案 2 :(得分:0)
webBrowser.Document.Forms[0].All.GetElementsByName("buttonname")[0].InvokeMember("click");
应该可以正常使用。