I created a webpage, and I want to access a html page’s javascript variable for R/W.
...
<script>
var _ANYINT = 0;
var _ANYOBJ = 0;
</script>
...
How can I read a variable?
function ReadInt(varName) : integer
Result := webbrowser.document.all.?????????? var Name ?????
end;
r := ReadInt('_ANYINT');
And how to write into?
Thanks:
dd
The
HTMLWindowinterface exposes anexecScriptfunction that permits the execution of javascript code inside the WebBrowser document. See http://delphi.about.com/od/adptips2006/qt/wb_execscript.htm , for example.Unfortunately,
execScriptdoes not allow for a result be returned.So, to access javascript data, you will need that in your javascript you write some function that puts the desired data into a hidden field in the page and then from your Delphi you access the field via WebBrowser. Here is some example code on how to do it. http://www.delphidabbler.com/articles?article=21&part=1#retval