如何在Delphi存取,更改网页中JavaScript 变量的值?(100分)

  • 主题发起人 vanguardwang
  • 开始时间
V

vanguardwang

Unregistered / Unconfirmed
GUEST, unregistred user!
如何在Delphi程序中(利用WebBrowser控件,已经得到IHtmlDocument2)更改当前网页中包含的
javascript全局变量值?
 
[:)]在网上找到了一个类似的问题, 可惜也没有答案
(http://textcontrol.com/tx/newsgroups/comp_lang_pascal_delphi_components_writing/2002/04/05/0003.htm)
Hi, I have used IHTMLDocument::get_Script() which returns a IDispatch for
the scripting engine. How can I get access the names of the functions
and global variables of scripts withing a HTML page? If I know the
name prehand, I can use IDispatch->GetIDsOfName() to get the DISPID of
particular variable or function. However, if I don't know the name, I
can't find way to retrieve the names.
 
想知道!!
 
UP,

要是能改,多好啊!
 
更改当前网页中包含的
javascript全局变量值?
 
得到window.external,通过这个实现脚本&&app的互相调用,可以参考
http://www.euromind.com/iedelphi/download/embedwb116b.zip
 
http://www.euromind.com/iedelphi/download/embedwb116b.zip


这个怎么用?
 
给个最简单的Demo,给分吧![:D][:D][:D]

假如index.htm中有个全局变量:g_nTest1 = 1;
现在要将g_nTest1的值改为 2;
代码如下:

/////////////////////////////////////////////
uses MSHtml;

//
procedure TForm1.Button1Click(Sender: TObject);
var
win: IHTMLWindow2;
begin
webbrowser1.navigate(extractfilepath(application.ExeName)+'index.htm');
win := IHTMLDocument2(WebBrowser1.Document).ParentWindow;
win.execScript('g_nTest1=2','javascript');
end;
 
顶部