具有 Webbrowser 控件和 Javascript 的 VBS 应用程序
我有一个带有网络浏览器控件的 VBS 应用程序。在此控件中,我打开一个包含 JavaScript 的 HTML 文件。该 JavaScript 只是将一个变量设置为值,如下所示:
var clicked = 3;
我是否有可能在我的 VBS 应用程序中使用此变量?我可以返回值吗?
谢谢你!
在我的 Webbrowswer 控件中,我使用事件 DocumentComplete? 在这种情况下我说:
Dim oScript As Object
set myVariables = oScript.clicked
? 如果我有多个全局变量,我该如何选择正确的一个? 如果我在 OnClick 事件中的 javascript 中设置此变量,则事件“DocumentComplete”不是正确的,或者? Viszal Basic Script 中不接受 Dim oScript As Object
行?
感谢您的帮助!
I have a VBS application with a webbrowser control. In this control I open an HTML file which contains JavaScript. This JavaScript just sets a variable to value, like this:
var clicked = 3;
Do I have any possibilty to use this variable in my VBS application? Can I return the value?
Thank you!
in my Webbrowswer control I use the event DocumentComplete?
And in this event I say:
Dim oScript As Object
set myVariables = oScript.clicked
?
If I have more than one global variable, how can I chose the right one?
And If I set this variable in javascript in an OnClick event the event "DocumentComplete" is not the right one, or?
And the line Dim oScript As Object
is not accepted in Viszal Basic Script?
Thank you for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这个答案可能不适用于 Visual Basic 6.0,但是,在 VB .NET 和 C# 中,您可以执行如下操作:WebBrowser1.Document.InvokeScript("eval", "clicked")。也许您可以在 Visual Basic 6.0 中找到类似的东西。
I know this answer may not be applicable to Visual Basic 6.0, but, in VB .NET and C# you do something like this: WebBrowser1.Document.InvokeScript("eval", "clicked"). Perhaps you can find something similar in Visual Basic 6.0.
VB6 擅长后期绑定,因此您不需要处理 IDispatch 和 DISPATCH_PROPERTYGET 等自动化内容。只需 Dim oScript As Object 并将其设置为 DocumentComplete 事件中的 webbrowser.document.script 即可。 DocumentComplete 也是替换元素处理程序的好地方,请参阅 处理html元素事件,如果你想接收元素事件,那么你可以调用oScript.clicked来获取全局变量的值。也就是说,除非您转在您的网络浏览器控件中的 IE9 模式 上,那么您需要处理 IDispatchEx 和 COM 疯狂。
从 Web 浏览器控件读取 Javascript 变量 是此问题的 C# 版本。
VB6 is good at late binding, so you do not need to deal with automation stuff like IDispatch and DISPATCH_PROPERTYGET. Just Dim oScript As Object and set it to webbrowser.document.script in the DocumentComplete event. DocumentComplete is also a good place to replace element handlers, see handle html element events, in case you want to sink element events, then you can call oScript.clicked to get the global variable's value. That is, unless you turn on the IE9 mode in your webbrowser control, then you need to deal with IDispatchEx and COM madness.
Read Javascript variable from Web Browser control is the C# version of this question.