分享

delphi的webbrowser如何访问网页中某个frame里的组件?

 独孤求财 2012-11-02

先取出对应frame的document,再取想要的元素,给你我写的函数,新人是应该带着进门的……


//框架获取
function GetDocument(Document:IHTMLDocument2;Index:integer):IHTMLDocument2;//框架获取
var frame_dispatch:IDispatch;
framed:IHTMLWindow2;
ole_index:OleVariant;
begin
ole_index:=Index;
frame_dispatch:=Document.Frames.ITem(ole_index);
if frame_dispatch <> nil then
begin
framed:=frame_dispatch as IHTMLWindow2;
result:=framed.Document as IHTMLDocument2;
end
else
begin
result:=nil;
end;
end;

//点击指定位置或名称的链接,或者给指定的名称或序号的元素赋值
procedure GetItem(Document:IHTMLDocument2;Index:String;IsClick:Boolean;State:integer;Value:string);
var IDoc1: IHTMLDocument2;
ielc: IHTMLElementCollection;
ihtml:IHTMLElement;
input:IHTMLInputElement;
TextArea:IHTMLTextAreaElement;
i:integer;
begin
Document.QueryInterface(IHTMLDocument2,iDoc1);
ielc:=idoc1.Get_all;
if(trystrtoint(Index,i))then
begin
if(IsClick)then
begin
ihtml:=ielc.item(strtoint(Index),0) as IHTMLElement;
ihtml.click;
end
else
begin
case State of
0 :
begin
input:=ielc.item(strtoint(Index),0) as IHTMLInputElement;
input.value:=Value;
end;
1 :
begin
TextArea:=ielc.item(strtoint(Index),0) as IHTMLTextAreaElement;
TextArea.value:=Value;
end;
end;
end;
end
else
begin
if(IsClick)then
begin
ihtml:=ielc.item(Index,0) as IHTMLElement;
ihtml.click;
end
else
begin
case State of
0 :
begin
input:=ielc.item(Index,0) as IHTMLInputElement;
input.value:=Value;
end;
1 :
begin
TextArea:=ielc.item(Index,0) as IHTMLTextAreaElement;
TextArea.value:=Value;
end;
end;
end;
end;
end;

这是我百度的技术博客,不懂可以去上边看,或者问……

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多