问题
I use TChromium. I assign AWebPageAsString
which is a static HTML page with a gray background color.
FBrowser := TChromium.Create(pnlHolder);
FBrowser.Visible := false;
FBrowser.Parent := TWinControl(pnlHolder);
FBrowser.Align := alClient;
FBrowser.OnBeforeBrowse := BrowserBeforeBrowse;
FBrowser.HandleNeeded;
FBrowser.FontOptions.RemoteFontsDisabled := true;
FBrowser.Browser.MainFrame.LoadString(AWebPageAsString, 'navigate:webpage');
When I start the application it is displayed first with white background and empty content and then my page gets displayed with gray background and actual content.
Is there a way to avoid this ? Maybe have a default background color ?
回答1:
Quite a late answer, I know, but it's at least an interesting topic. To change default browser's background color you can use a custom stylesheet. It sounds good, but it has one big weakness - when you navigate to a page that has e.g. no stylesheet defined, your custom one will be applied. But if you know that you'll browse e.g. only your pages in a certain style, it might be even advantage, since then you can leave the style definitions defined in that default custom style.
So to create a browser with a black background (using the style described below) you can use this code:
procedure TForm1.FormCreate(Sender: TObject);
const
CSSHeader = 'data:text/css;charset=utf-8;base64,';
CSSBase64 = 'Ym9keSB7YmFja2dyb3VuZC1jb2xvcjpibGFjazt9';
begin
Chromium1.UserStyleSheetLocation := CSSHeader + CSSBase64;
Chromium1.Options.UserStyleSheetEnabled := True;
Chromium1.ReCreateBrowser('about:blank');
end;
The CSSBase64
constant used in the above code is the following stylesheet encoded to Base64:
body {background-color:black;}
来源:https://stackoverflow.com/questions/8645814/how-to-change-default-background-color-for-tchromium-component