We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


Call Javascript from VB6 Active X control

Medium Priority
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?


Watch Question

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


Do you have an example?
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


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.

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).  

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.