uses
SHDocVw, MSHTML, ActiveX;
function getFrameToName(const IE: IWebBrowser2; SearchName : string): IWebBrowser2;
var
bFind : Boolean;
function IterateFrames(const IE: IWebBrowser2; ASearchName : string): IWebBrowser2;
var
Doc: IHTMLDocument2;
Container: IOleContainer;
Enumerator: ActiveX.IEnumUnknown;
Unknown: IUnknown;
Browser: IWebBrowser2;
Fetched: Longint;
SubDoc: IHTMLDocument2;
nFrameCnt : Integer;
FrameColl :IHTMLFramesCollection2;
begin
Result := nil;
nFrameCnt := 0;
if (Assigned(IE.Document)) and (Supports(IE.Document, IHTMLDocument2, Doc)) then
begin
FrameColl := Doc.frames; //넘어온 인터페이스에서 Frame 가져오기
if FrameColl = nil then Exit;
if (Supports(Doc, IOleContainer, Container)) and (Container.EnumObjects(OLECONTF_EMBEDDINGS, Enumerator) = S_OK) then
begin
while (Enumerator.Next(1, Unknown, @Fetched) = S_OK) and not bFind do
begin
if (Supports(Unknown, IWebBrowser2, Browser)) and (Supports(Browser.Document, IHTMLDocument2, SubDoc)) then
begin
if nFrameCnt < FrameColl.length then
begin
if ASearchName = FrameColl.item(nFrameCnt).name then //프레임명이 일치하면 재파싱한 인터페이스 리턴
begin
bFind := True;
Result := Browser;
end
else
IterateFrames(Browser, ASearchName);
Inc(nFrameCnt);
end;
end;
end;
end;
end;
end;
begin
bFind := False;
Result := IterateFrames(IE, SearchName); //프레임 검색 후 리턴
end;
Ex)
var
IE : IWebbrowser2;
begin
ShowMessage((getFrameToName(IE, 'mainframe').Document as IHTMLDocument2).body.innerHTML);
end;