在 vb6 中的 WebBrowser 控件中检索 Javascript 函数的返回值 [英] Retrieve return value of a Javascript function in the WebBrowser control in vb6

查看:21
本文介绍了在 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

这篇关于在 vb6 中的 WebBrowser 控件中检索 Javascript 函数的返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆