Execute JavaScript in a Web Browser Control using VB6

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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


.



Relevant Pages

  • Re: More bollocks from biggots
    ... So if you choose to visit sites that execute JavaScript from "Who knows ... Google as the Google Mail HTML/Javascript does. ... javascript response stored in memory. ...
    (comp.os.vms)
  • Re: Misspelling Can Bite You
    ... I misspelled the name of the control variable for a switch. ... JavaScript was quite happy to execute the code. ... Barring `this' referring to a host object or `bar' being a specially ...
    (comp.lang.javascript)
  • Re: timer in front page
    ... One solution would be to use JavaScript to submit the form when the ... it would execute in 30 minutes. ... > WebPage with a timer. ... > you put a timer into the WebPage? ...
    (microsoft.public.frontpage.client)
  • Re: Access JavaApplet through DOM
    ... I told him I knew how to execute a JavaScript function on a ... web page hosted by IE's Web Browser control, ... didn't know how to access a child object on the page. ... execute with the line below: ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Urgent - How can we automate clicking of java script prompts through IE object model
    ... I could consider re writing my unit test framework to use the web ... browser control. ... Would there be any disadvantaeg in doing this? ... Currently I can execute the tests using the Visible attribute to ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)