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

jre*_*rey 3 vb6 webbrowser-control

我有一个vb6应用程序,

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

我目前的职能是

v = WebBrowser1.Document.parentWindow("v = function(){return callOther();};v()");
Run Code Online (Sandbox Code Playgroud)

然后,我需要v值.. posible值是javascript函数.

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

Ily*_*sov 8

  1. 将JavaScript函数的返回值分配给JavaScript变量.
  2. 使用execScript方法WebBrowser.Document.ParentWindow来调用您的JavaScript代码.
  3. 现在WebBrowser.Document.Script.<JavaScript variable name, case-sensitive> 在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
    
    Run Code Online (Sandbox Code Playgroud)