ok - thanks... but how can I do this programmatically...
C#
webBrowser1.Document.... ? Could you please gimme a hint?
btw. is it possible to insert a code snipplet to a special location within
the html document, to modify or override for example the JavaScript Code with
my own code?
Thanks in advance, Randy
R> ok - thanks... but how can I do this programmatically...
You may use JScript.NET for that.
I find it to be the most convenient way. Make a DLL with the code on JScript.NET
that works with the browser, and call it whenever needed to say something
to the browser object. In that case webBrowser1.Document would be just the
HTML "document" object.
R> C#
R> webBrowser1.Document.... ? Could you please gimme a hint?
In C# it's not that convenient. Generally …
webBrowser1.Document.GetType().Invoke("methodname", …)
see help for System.Type.Invoke.
R> btw. is it possible to insert a code snipplet to a special location
R> within the html document, to modify or override for example the
R> JavaScript Code with my own code?
What do you want to do? Call your managed code from the browser script?
Two ways to do that, the first is to use the window.external which may point
to any object, including a C# one. Unfortunately, it's not easy to set the
external property to point to your object.
Another way is to assign a delegate to a property of some HTML element using
setAttribute. Then you may getAttribute from browser script and call it.
However, that must be a OLE delegate not .NET delegate. One can be provided
by JScript.NET, just set the attribute to one of your member functions, and
will be callable:
// in JS.NET
webBrowser1.Document.body.setAttribute("Callback", this.CallbackFunction);
// in browser script
var callback = document.body.getAttribute("Callback");
callback(param1, param2); // .NET method CallbackFunction will be called
However, that all is hardly needed — you may attach to an HTML element event
from managed JScript.NET code just the same way as from the browser script,
like:
document.getElementById("myButton").attachEvent("onclick", this.MyButtonClickHandler);
- or -
document.getElementById("myButton").onclick = this.MyButtonClickHandler;
From C#, all of the above is very hard to do.
(H) Serge
Randy - 03 May 2005 21:52 GMT
Hi Serge,
thanks a lot for your reply! It helps me a lot understanding the DOM!
Greetings from Germany, Randy
> R> ok - thanks... but how can I do this programmatically...
>
[quoted text clipped - 50 lines]
>
> (H) Serge