在 vb6 中的 WebBrowser 控件中检索 Javascript 函数的返回值

问题描述:

我有一个 vb6 应用程序,

I have a vb6 application,

我使用 WebBrowser 脚本进行函数调用,但我需要获取该函数的返回值

I make a function call with WebBrowser script but I need to get the return value of that function

我目前的职能是

v = WebBrowser1.Document.parentWindow("v = function(){return callOther();};v()");

然后,我需要 v 值.. 可能的值是 javascript 函数.

Then, i need the v value.. the posible value is javascript function.

如何检索v",我的测试响应出现错误 91(未设置块变量的对象变量).我是 vb6 的初学者.

How to retrieve "v", my test response with Error 91 (Object variable with block variable no set).. i'm beginner with vb6.

  1. 将 JavaScript 函数的返回值分配给 JavaScript 变量.
  2. 使用WebBrowser.Document.ParentWindowexecScript方法来调用您的 JavaScript 代码.
  3. 现在通过检索变量的值WebBrowser.Document.Script.在VB6中.

  1. Assign return value of your JavaScript function to JavaScript variable.
  2. Use execScript method of WebBrowser.Document.ParentWindow to call your JavaScript code.
  3. Now retrieve value of the variable via WebBrowser.Document.Script.<JavaScript variable name, case-sensitive> in VB6.

Private Sub cmdJsFunc_Click()
    Dim retVal As String

    Call WebBrowser1.Document.parentWindow.execScript("v = function(){return 3.14;}; tempJsVar=v();")
    retVal = WebBrowser1.Document.Script.tempJsVar

    MsgBox retVal
End Sub