Calling HTML JScript from C# app

G

Guest

Hi
Can some good soul help on this. I need to call jscript functions from C#.
I have hosted a web control and displayed an html page successfully, but
just can't find a way to call jscript functions or set some var in the html.
There are some sample code in C++ using IDispatch but these are
beyond me. Looked at Tim Anderson's work on HTMLEditor but couldn't find any
example on calling jscript function. Read somewhere that the browser control
putproperty does not work for embed control.

Any help or sample code much appreciated.

regards
benc
QMatrix
 
S

Sam Martin

you need to use MSHTML. from the WebControl you can get to the document.

From here you need to use the DOM to do stuff with the document.

You can actually do anything here, and the MSHTML COM lib provides support
for calling submit methods, etc. with the HTML document.

This is all from memory and it's been a while, but start by adding a
reference in your project to the MSHTML lib, then you should be able to suss
it out from there.

HTH
Sam
 
G

Guest

thanks, sam
i know this and is using the mshtml com and IHTMLDocument2, etc. but
just can't see how to call a jscript function. The putproperty function is
the way to go, but just does not work with the browser control.

any other help?
thanks
 
G

Guest

Hi Sam
Many thanks. You are most helpful.
I got it going now and only to find other issues. eg. plugin like SVG3 does
not quite behave the same in a hosted environment vis-a-vis in IE.

Also, any chance you know how to call C# from script? An example I had is
to set the script var with window.SetProperty(...,this) and then in the script
calling var.C#routineName should work. BUT not for mshtml.

thanks, regards
benc
 
S

Sam Martin

hmm, i think the simple answer is you can't.

but you can handle the browsers events, like title change. as there's no
title shown it's one way you could pass info / exec commands in the host
app, one way i've made it work in an ancient version of PowerBuilder (a 4GL)
is to do this, setting the browser's title to be a specific string command,
i.e. "DOSOMETHING" and handling the titlechanged event.

just an idea

sam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top