Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / JScript / May 2005

Tip: Looking for answers? Try searching our database.

Getting value of JavaScript variable in embedded WebBrowser Contro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Randy - 25 Apr 2005 14:09 GMT
Hi,

is it possible to programmatically (from C# or VisualBasic) get the value of
a JavaScript
Variable from a JavaScript running inside the embedded WebBrowser Control?

Thanks in advance, Randy
Bruce Barker - 25 Apr 2005 17:45 GMT
javascript global variables can be refered to as window.VarName

-- bruce (sqlwork.com)

> Hi,
>
[quoted text clipped - 4 lines]
>
> Thanks in advance, Randy
Randy - 26 Apr 2005 19:42 GMT
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

> javascript global variables can be refered to as window.VarName
>
[quoted text clipped - 8 lines]
> >
> > Thanks in advance, Randy
Serge Baltic - 27 Apr 2005 17:25 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.