Call Javascript from VB6 Active X control

Posted on 2009-02-10
Last Modified: 2013-11-18
Ok I am a little rusty on VB6 because I have spent too much time in .net.

So my question is how can I call some javascript from a vb6 active x control that is placed on a page?


Question by:jmarbutt

    Expert Comment

    Use the Windows API CreateProcess to launch your browser with the java script name in the command line parameter.
    LVL 2

    Author Comment

    Do you have an example?

    Expert Comment

    Found an easier way. Use the shell command:

    Shell "C:\Program Files\Internet Explorer\Iexplore.exe C:\test\JS Test.htm"

    The first part is the path to the browser: C:\Program Files\Internet Explorer\Iexplore.exe
    The second part is the path to the script file: C:\test\JS Test.htm
    LVL 2

    Author Comment

    I think we are going in circles. Let me see if I can explain it a little better.

    I have a page that has some javascript and an activex control, I want this active x control to call the javascript that is on the page with it, not open another browser window with in the active x control.


    Accepted Solution

    Sorry about that.  There is no easy way that I know of to have an ActiveX control talk to a java script routine.  The ActiveX control is an executable and is thus separate from the Internet Explorer Executable.  Though you can display the ActiveX control on a web page, its still a separate executable.   If you were to launch a web browser instance with your ActiveX control, it might make it easier though Im not sure about that.   So the only way I know how to do it would be to automate your web browser. The traditional way to do that is to use the SendMessage API.   With the SendMessage API, you can send keystrokes(tab, enter etc.) and mouse clicks to any window you can get the handle on.   So what you do is tie a Java Script control like a button(which can be hidden) to your java script code that will get executed when your ActiveX control sends a mouse click to it.

    Unfortunately, I dont have an example of how to code up the SendMessage this right now but you should be able to locate some examples on the web.   I do remember though that when you are sending messages, you have to send both the Key or Click down and the Key or Click up separately.  You also need to give the application time to respond so dont send messages  right after one another but give few milliseconds of delay so it can process them.  For example, send the Key down message, wait 10 ms and then send Key up message. So you have to call the SendMessage API twice for every message.   Note that you can use the tab key to set the focus of where you are sending your messages to(i.e. the button).  

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now