我正在使用网页浏览器C# 中的控件加载网页,需要调用返回字符串值的 JavaScript 函数。我有一个解决方案可以使用调用脚本方法,我也尝试了很多,但都失败了。
你能具体说明什么失败了吗?
我的下面的示例由一个带有 Web 浏览器和按钮的表单组成。
名为 y 的对象最后有一句话“我做到了!”。所以对我来说它有效。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
webBrowser1.DocumentText = @"<html><head>
<script type='text/javascript'>
function doIt() {
alert('hello again');
return 'i did it!';
}
</script>
</head><body>hello!</body></html>";
}
private void button1_Click(object sender, EventArgs e)
{
object y = webBrowser1.Document.InvokeScript("doIt");
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)