在VB.NET中嵌入Javascript

时间:2015-06-04 14:15:54

标签: javascript vb.net

我需要在VB.NET中添加javascript代码;

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Me.WebBrowser1.Document.InvokeScript("javascript:(function(){document.body.appendChild(document.createElement('script')).src='http://example.com/api.php?p=mail';})();")

我使用此javascript代码填写网站表单(在Firefox浏览器上添加书签)

javascript:(function(){document.body.appendChild(document.createElement('script')).src='http://example.com/api.php?p=mail

现在我想在VB.Net浏览器中使用它,但是当我做Invoke Script时没有任何反应。我也试过其他方法,但不去。

1 个答案:

答案 0 :(得分:0)

尝试:

WebBrowser1.Document.parentWindow.execScript "javascript:(function(){document.body.appendChild(document.createElement('script')).src='http://example.com/api.php?p=mail';})();", "JScript"

VBForums ...