delphi的webBrowser操作HTML研究

测试例子:

外网电脑D:\TEST\delphiTest\webbrowsetest

参考文档:

delphi 操作WebBrowser 元素值
http://hi.baidu.com/kinglike/item/c4608a8e55313f874514cf5c

delphi中WEBBrowser网页JS函数调用delphi函数
http://blog.csdn.net/iseekcode/article/details/4740269

webbrowser精华内容
http://blog.csdn.net/iseekcode/article/details/4740367

delphi 向webbrowser打开的网页中插入js命令
http://blog.csdn.net/iseekcode/article/details/4740286

 

1.获取WEB控件值

function TForm1.fgetValue(editName: string): string;
var
  i:integer;
  Doc:IHTMLDocument2;
  input:OleVariant;
  userinputelement,pwdinputelement,ValidateElement:ihtmlinputelement;
  ValidateImage: IHTMLImgElement;
  imagecount:integer;
  form:ihtmlformelement;
  myitem:Olevariant;
begin
Doc:=WebBrowser1.document as ihtmldocument2;
  if doc=nil then exit;

// 第一种方式
  userinputelement:=(doc.all.item(editName,0) as ihtmlinputelement);
  Result :=  userinputelement.value;


end;

2.设置WEB控件值

procedure TForm1.setValueClick(Sender: TObject);
var
  i:integer;
  Doc:IHTMLDocument2;
  input:OleVariant;
  userinputelement,pwdinputelement,ValidateElement:ihtmlinputelement;
  ValidateImage: IHTMLImgElement;
  imagecount:integer;
  form:ihtmlformelement;
  myitem:Olevariant;
begin
Doc:=WebBrowser1.document as ihtmldocument2;
  if doc=nil then exit;

// 第一种方式
  userinputelement:=(doc.all.item(‘userName‘,0) as ihtmlinputelement);
  userinputelement.value:=‘ADMIN‘;

  userinputelement:=(doc.all.item(‘password‘,0) as ihtmlinputelement);
  userinputelement.value:=‘1‘;


end;

3.WEB调用DELPHI

procedure TForm1.WebBrowser1BeforeNavigate2(ASender: TObject;
  const pDisp: IDispatch; const URL, Flags, TargetFrameName, PostData,
  Headers: OleVariant; var Cancel: WordBool);
begin
//  showmessage(url);
  if pos(‘qwbbLocatePage.action‘, url) > 0 then
  begin
    ShowMessage(fgetValue(‘userName‘));
    Cancel:= true;
  end;
end;

delphi的webBrowser操作HTML研究,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。