Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Execute JavaScript in a Web Browser Control using VB6

2,564 views
Skip to first unread message

Julie

unread,
Dec 9, 2007, 10:48:37 PM12/9/07
to
I was searching the new groups trying to find an answer to the
question, how do I access a child object of a webpage hosted in a Web
Browser Control (shdocvw.dll)? The JavaScript group gave me the most
grief and least amount of actual help.

What I was trying to accomplish was the executing of a function
exposed by a JavaApplet using JavaScript. A company called Deaja has
a product call ViewOne Pro. ViewOne Pro is a JavaApplet that will
allow 300 different file types to rendered (pdf, FileNet TIFF's,
etc). For example, a web page that contains this applet can place
code behind the click event of a button that will allow the user to
zoom in on an image:

document.viewOne.zoomIn();

My question was how do I execute this line of code in VB6 using the
Web Browser control? Using the line below, I could execute a
JavaScript function which would serve as a wrapper to the line above:

Me.wbImageViewer.Document.parentWindow.execScript "MyWrapperFunc();",
"JScript"

That would work, but seem kluge and the web page developer would have
to develop a function on the page for each function I wanted to
perform. First of all, my application wasn't the only one using this
page and it made for a thicker client. Then it hit me. If I could
execute a JavaScript function, why not create an inline / no name /
self executing function?

Me.wbImageViewer.Document.parentWindow.execScript "(function()
{document.ViewONE.zoomIn();}());", "JScript"

Freakin awesome!!! Now I do not have to rely on the web page owner to
implement JavaScript wrapper functions just for me and since this code
is not stored on the page after execution, the page remains thin and
clean. I want to say it even offers a layer of security because the
code doesn't stay on the page available to the pages source. I can
even create a function that takes parameters:

Me.wbImageViewer.Document.parentWindow.execScript "(function(parmName)
{document.ViewONE.getPage(parmName);}('36'));", "JScript"

I'm posting this solution primarily because it took me a while to come
up with an answer and in the event someone else needed this solution
(you can still host a Web Browser control in a .Net Win Form
application), here is the answer. Sharing is a wonderful thing :-)

Cheers,

J


sle...@gmail.com

unread,
Jul 9, 2014, 9:18:21 AM7/9/14
to
Hi
use this structure:
WebBrowser1.Navigate2 "Javascript:document.viewOne.zoomIn();void 0"
regurds

ralph

unread,
Jul 9, 2014, 11:33:32 AM7/9/14
to
It's good to see the OP receiving on answer after only seven years.
Hopefully your deliveries are somewhat more timely for your current
employer.

-ralph
0 new messages