possible to call javascript from IE hosted winform control ?

  • Thread starter Thread starter Dave Brown
  • Start date Start date
D

Dave Brown

Hello everyone,

Can anybody tell me if it is possible to call a javascript function in the
html from a embedded winform control ?
Note. this is not ASP, just a plain html page with a javascript function
such as
function Hello(name)
{
alart("Hello "+name);
}

and then in the body of the html is the <form> and <object> tag...

Thanks in advance...
 
Hi Dave,

what the control hosts html?
If you use WebBrowser control you can call any JS funtion like the
following:

WebContorl1.Document.parentWindow.execSript("functionName(param1,param2...)"
)
or
WebContorl1.Document.parentWindow.functionName(param1,param2...) if you need
to get returned value.

For, e.g., DHTMLEdit control the call is
DHTMLEdit1.DOM.Document.parentWindow etc....

You should get the reference to document instance (instance of HTMLDocument
class from mshtml) representing your html.

But what the WindowsForm control do you use?

Best regards.
 
Hi Dave,
it is possible. You can do it by raising events from IE hosted usercontrol.
In this scenario control should export COM interface. Java script can catch
these events. However there are some security constraints, meaning that some
extra configuration should be done on the clients (not nice, of course).

There was a thread in this group: "Handling WinForm events (IE-hosted) with
a JavaScript sink"
There was some good link... now I found
http://www.codeproject.com/dotnet/javanet.asp, which is also not bad.
Microsoft has also the following article:
http://msdn.microsoft.com/msdnmag/issues/02/01/UserCtrl/default.aspx, take a
closer look at chapter Handling Events

Igor Kramaric
 
Hi thanks for the replies,

Extra configuration is what I was trying to avoid. So far the control does
everything I need it to do except play sounds. This is why I want to use the
javascript call to open up a window to call the URL that the mp3 sound file
is located at.

This I thought would be the easiest way to achieve sound playback, other
methods i've tried dont work correctly likewise due to security, DirectX
AudioVideoplayback, DirectShow, Windows Mediaplayer controls.

I used to do this kind of thing quite easily with activeX as it would let me
Shellexecute the url, as long sa the user said they trusted my signed
control i could do everything i needed to do.

Rgds,

Dave.
 
Back
Top