我使用标签“脚本”制作了 HtmlElement 实例,它不允许我设置 InnerHtml 成员。
这是为什么?
HtmlElement tempElement = wbMain.Document.CreateElement("script");
wbMain.Document.GetElementsByTagName("head")[0].AppendChild(tempElement);
tempElement.SetAttribute("type", "text/javascript");
tempElement.InnerHtml = "function test(a){document.getElementById('test').value = a;}";
这样做的最终目标是将 JavaScript 代码注入(inject)网页,并使用 webbrowser 表单的 htmldocument 中的 InvokeScript 函数从应用程序中执行它
请您参考如下方法:
您真的应该使用 Page.ClientScript 方法。
例如:
string myScript = "function test(a){document.getElementById('test').value = a;}";
Page.ClientScript.RegisterClientScriptBlock( typeof( Page ), "someScriptName", myScript, true );
