我有一個VB.Net Windows應用程序項目。VB.Net WebBrowser調用JavaScript函數不起作用
這是下面的VB.Net代碼片段。
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'webBrowser1 is the variable of the System.Windows.Forms.WebBrowser class.
webBrowser1.Navigate("file:///" & IO.Path.GetFullPath(".\test.html"))
'not working
webBrowser1.Document.InvokeScript("test")
這是下面的test.html代碼片段。
<html>
<title>test</title>
<body>
<script>
function test(){
alert('test');
}
</script>
</body>
</html>
此應用程序不會在javascript測試函數中彈出「測試」警報。
如何解決這個問題?
我通常用它來調用腳本:'ClientScript.RegisterStartupScript(Me.GetType(),「 RunScriptRun「,」「)'。讓我知道它是否適用於你的情況。 –
@AllenBinuya:只適用於ASP.NET,不適用於WinForms。 –
哦..對不起,我無法區分WinFoms和ASP.NET。 –