How to access javascript variable via MSHTML in Dephi?
- From: FMchwk@xxxxxxxxx
- Date: Fri, 16 May 2008 19:56:14 -0700 (PDT)
Hi there,
My webpage is written in HTML including a very simple javascript
function in which a variable myvar is defined. Now, I am using
Delphi's TWebbrowser to access the page and trying to access the
change of the variable with MSHTML interface. Here is my code
var
Doc: IHTMLDocument2;
HTMLWindow: IHTMLWindow2;
JSFn: string;
begin
Doc := AutoWebBrowser2.Document as IHTMLDocument2;
if not Assigned(Doc) then Exit;
HTMLWindow := Doc.parentWindow;
if not Assigned(HTMLWindow) then Exit;
try
JSFn := 'if (myvar==3) {alert("Done");}';
HTMLWindow.execScript(JSFn, 'JavaScript'); // this run without any
problem
except
showmessage('error');
end;
end;
I can even change the script to modify the variable like
JSFn := 'myvar=-2;';
However, what my need is to get the value of myvar and return it to
Delphi. I try to collect all elements of IHTMLDocument2 but seems not
found any function or property related to the variable defined in
javascript. How can I get the value return by a javascript function?
Thanks
.
- Follow-Ups:
- Re: How to access javascript variable via MSHTML in Dephi?
- From: Igor Tandetnik
- Re: How to access javascript variable via MSHTML in Dephi?
- Prev by Date: Re: Re:How to make a Chevron on an IDeskBand toolbar
- Next by Date: How can I capture the error message of Iwebbrowser?
- Previous by thread: Re:How to make a Chevron on an IDeskBand toolbar
- Next by thread: Re: How to access javascript variable via MSHTML in Dephi?
- Index(es):
Relevant Pages
|