Call Javascript from VB6 Active X control

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?


Who is Participating?
TheSaint777Connect With a Mentor Commented:
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).  
Use the Windows API CreateProcess to launch your browser with the java script name in the command line parameter.
jmarbuttAuthor Commented:
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
jmarbuttAuthor Commented:
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.