核心提示:procedure TDxSkinWebBrowser.ReSetWebSize;var WebClientWidth,WebClientHeight: Integer; MaxScrollWidth...
procedure TDxSkinWebBrowser.ReSetWebSize;var
WebClientWidth,WebClientHeight: Integer;
MaxScrollWidth, MaxScrollHeight: Integer;
webPoint: TPoint;
begin
if (FWebBrowser.Document <> nil) and ((FWebBrowser.Document as IHTMLDocument2).body <> nil) then
begin
{先获得页面的最大高度}
if (FScrollBars = ssVertical) or (FScrollBars = ssBoth) then
begin
if IsW3CStd then //如果是W3C标准
MaxScrollHeight := FWebBrowser.oleobject.document.documentelement.ScrollHeight
else
MaxScrollHeight := (FWebBrowser.Document as IHTMLDocument2).body.getAttribute('ScrollHeight', 0);
if MaxScrollHeight > FWebBrowser.Height then //总高度大于显示高度度出现滚动条
begin
if IsW3CStd then
begin
WebClientHeight := FWebBrowser.oleobject.document.documentelement.ClientHeight;
webPoint.Y := FWebBrowser.oleobject.document.documentelement.scrollTop;
end
else
begin
WebClientHeight := (FWebBrowser.Document as IHTMLDocument2).body.getAttribute('ClientHeight', 0);
webPoint.Y := ((FWebBrowser.Document as IHTMLDocument2).body as IHTMLElement2).scrollTop;
end;
FVScrollBar.SetRange(0,MaxScrollHeight,webPoint.Y,WebClientHeight);
FVScrollBar.Visible := true;
end else FVScrollBar.Visible := False;
end;
if (FScrollBars = ssHorizontal) or (FScrollBars = ssBoth) then
begin
if IsW3CStd then //如果是W3C标准
MaxScrollWidth := FWebBrowser.oleobject.document.documentelement.ScrollWidth
else
MaxScrollWidth := (FWebBrowser.Document as IHTMLDocument2).body.getAttribute('ScrollWidth', 0);
//总宽度大于显示宽度,出现滚动条
if MaxScrollWidth > FWebBrowser.Width then
begin
if IsW3CStd then
begin
WebClientWidth := FWebBrowser.oleobject.document.documentelement.ClientWidth;
webPoint.x := FWebBrowser.oleobject.document.documentelement.ScrollLeft;
end
else
begin
WebClientWidth := (FWebBrowser.Document as IHTMLDocument2).body.getAttribute('clientWidth', 0);
webPoint.x := ((FWebBrowser.Document as IHTMLDocument2).body as IHTMLElement2).scrollLeft;
end;
FHScrollBar.SetRange(0,MaxScrollWidth,webPoint.X,WebClientWidth);
FHScrollBar.Visible := True;
end else FHScrollBar.Visible := False;
end;
end;
end;