您将不得不迭代all
而不是styleSheets
查看元素的样式。
uses mshtml;
Procedure WebBrowserCreateStringListImagesFromElementStyles(const AWebBrowser: TWebBrowser; ResultList: TStrings; NoUrl: Boolean = false);
var
nCount: Integer;
element: IHTMLElement;
elements: IHTMLElementCollection;
bgImage: String;
begin
Assert(Assigned(AWebBrowser.Document) and Assigned(ResultList));
if Assigned(AWebBrowser.Document) then
begin
elements := (AWebBrowser.Document as IHTMLDocument2).all;
for nCount := 0 To Pred(elements.Length) do
begin
element := elements.item(nCount, '') as IHTMLElement;
if (element.style.backgroundImage <> '') and (UpperCase(element.style.backgroundImage) <> 'NONE') then
begin
bgImage := element.style.backgroundImage;
if NoUrl then
begin
if Pos('URL(', UpperCase(bgImage)) = 1 then
begin
Delete(bgImage, 1, Length('URL('));
if Pos(')', bgImage) = Length(bgImage) then
Delete(bgImage, Length(bgImage), 1);
end;
end;
ResultList.Add(AnsiLowerCase(bgImage));
end;
end;
end;
end;