大家好:
请教一下,现在做一个工具,向网页发包。而网页向服务器发的内容是经过网页前台加密的,服务器发过来的包也是加密,经过网页前台解密再显示的,网页源码里能看到加密和解密的函数,那我要向服务器发包的话,应该也是要加密。问题是delphi里能不能调用网页的加密/解密函数,这个应该怎样去调啊?并且函数名可能要通过字符串来传达,例如这个网:http://www.qianxibei.com/member/index.html
请教一下,现在做一个工具,向网页发包。而网页向服务器发的内容是经过网页前台加密的,服务器发过来的包也是加密,经过网页前台解密再显示的,网页源码里能看到加密和解密的函数,那我要向服务器发包的话,应该也是要加密。问题是delphi里能不能调用网页的加密/解密函数,这个应该怎样去调啊?并且函数名可能要通过字符串来传达,例如这个网:http://www.qianxibei.com/member/index.html
解决方案 »
- delphi如何读取获得C程序中Main函数的argc、argv
- 需要DBdatatimepicker控件 而且日期显示为当天开始 明一大早急用
- 寻求解决问题的方法,谢谢了!!!!
- RealLike RealLike RealLike 进来接分!
- 在同一张access2000表中复制记录,并把这些复制出的记录的一个字段Ft的值全部置为'TTTTT',该怎样实现?
- 请问这样的文件怎么拷贝??解决马上给分!
- 第三方组件skinengine,dxtreeview安装后如何使用的问题。
- 朋友有个软件要送上去审批,请问这个软件的文档怎么写?
- 高手请了,我怎样用TADOQUERY控件同时对几个表中的数据查询后的结果进行更新
- D7 tmemo 读入指定文档内容跟修改后保存内容
- 编译好的delphi程序,需要安装什么软件可以使其支持数据库
- 在不明确注册表键值类型的情况下如何读取键值信息?
How to call JavaScript functions in a TWebBrowser from Delphi 如何用Delphi在TWebBrowser中调用JavaScript
Rewritten by tamsun
Source From delphidabbler.com
方法介绍
在TWebBrowser中调用脚本的办法是调用Html文档相关的对象窗口中的execScript方法。至于什么是和Html Document相关的对象窗口,后面的代码中用到的IHTMLWindow2就是。execScript函数定义如下: function execScript(const code: WideString; const language: WideString): OleVariant;参数code是一个脚本函数的完整调用形式的字符串,例如有一个JavaScript函数定义为:
function foo(param1),则 code="foo(param1)"。
参数language表示脚本的类型,例如 language="JavaScript"
首先,获取浏览器组件的文档对象;然后通过该文档对象的ParentWindow属性来获取窗口对象。最后通过该窗口对象来调用execScript即可。下面就给出一个简单的实现示例。
实现示例
uses
MSHTML;
procedure TForm1.CallFoo(S: string; I: Integer);
{ Calls JavaScript Foo() function }
var
Doc: IHTMLDocument2; // current HTML document
HTMLWindow: IHTMLWindow2; // parent window of current HTML document
JSFn: string; // stores JavaScipt function call
begin
// Get reference to current document
Doc := WebBrowser1.Document as IHTMLDocument2;
if not Assigned(Doc) then
Exit;
// Get parent window of current document
HTMLWindow := Doc.parentWindow;
if not Assigned(HTMLWindow) then
Exit;
// Run JavaScript
try
JSFn := Format('Foo(''%s'',%d)', [S, I]); // build function call
HTMLWindow.execScript(JSFn, 'JavaScript'); // execute function
except
// handle exception in case JavaScript fails to run
end;
end;
实例演示
整个实例包括两部分: 网页文件test.html:文件内有一个JavaScript函数SetFont。该函数通过下拉框来选择字体,然后点击”set font“按钮来改变页面字体。
Delphi端程序:通过TWebbrowser来显示页面,并演示如何调用页面内的Javascript函数。
Test.html:
<html>
<head>
<title> Demo for call Javascript from Delphi
</title>
<script type="text/javascript">
<!--
function SetFont(fontname)
{
document.body.style.fontFamily = fontname;
}
-->
</script>
</head><body>
demo of calling Javascript from Delphi
<form>
<select size=1 name="selfont">
<option value="Verdana" selected>Verdana</option>
<option value="Arial">Arial</option>
<option value="Courier New">Courier New</option>
<option value="Tahoma">Tahoma</option>
</select>
<input type="button" value="set font" name="btn1"
onclick="SetFont(selfont.value)">
</form>
</body>
</html>
Delphi控制Javascript uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls, Mshtml;type
TForm1 = class(TForm)
btnCallJS: TButton;
cmbFonts: TComboBox;
WebNav: TWebBrowser;
procedure FormShow(Sender: TObject);
procedure WebNavDocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
procedure btnCallJSClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormShow(Sender: TObject);
begin
// Disable button
btnCallJS.Enabled := false;
// Load the Html page
WebNav.Navigate(ExtractFilepath(Application.ExeName)
+'test.html');
end;procedure TForm1.WebNavDocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
// When complete loading Html page, enable button
btnCallJS.Enabled := true;
end;// Call the Javascript in Html page
procedure TForm1.btnCallJSClick(Sender: TObject);
var
// current Html document
Doc : IHtmlDocument2;
// parent window of current Html document
HtmlWnd : IHtmlWindow2;
// Javascript function name including arguments
JsFnc : string;
begin
// Get reference to current document
Doc := WebNav.Document as IHtmlDocument2;
if not assigned(Doc) then
exit;
// Get parent window of current Html document
HtmlWnd := Doc.parentWindow;
if not assigned(HtmlWnd) then
exit;
// Run Javascript
try
JsFnc := 'SetFont(''' + trim(cmbFonts.Text) + ''')';
HtmlWnd.execScript(JsFnc, 'JavaScript');
except
Showmessage('Call JavaScript failed!');
end;
end;end.