Retrieve return value of a Javascript function in the WebBrowser control in vb6

[亡魂溺海] 提交于 2019-11-29 23:06:48

问题


I have a vb6 application,

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

my current function is

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

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

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


回答1:


  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
    



回答2:


Try:

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


来源:https://stackoverflow.com/questions/9005914/retrieve-return-value-of-a-javascript-function-in-the-webbrowser-control-in-vb6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!