views:

78

answers:

2

I found a strange behavior in the component TwebBrowser, when I load certain pages they are shown with larger fonts. different from what is used in internet explorer.

see these sample images

Here in this link http://docwiki.embarcadero.com/RADStudio/en/Main_Page is loaded with larger fonts in TWebBrowser and with small fonts (another style) in IE.

alt text

this page http://stackoverflow.com/ is loaded with same style in the TWebBrowser component and IE.

alt text

I tried it on different machines and same thing happens.

how can i fix this behavior ? this is a problem with a CSS?

+1  A: 

I think the problem is that the TWebBrowser component is running Internet Explorer in compatibility mode. Indeed, if you open the docwiki page in Internet Explorer 8 and later, the fonts are small and pleasant, in contrast to how they look in the TWebBrowser. But if you click the "Compatibility View" button in the Internet Explorer window, you will get the same large text as you do get in the TWebBrowser component. (It is well-known that IE6 use too large text.)

According to this MSDN blog entry and the MSDN docs, to control the compatibility mode of the TWebBrowser control, use the registry:

procedure TForm3.FormCreate(Sender: TObject);
begin

  with TRegistry.Create do
    try
      RootKey := HKEY_CURRENT_USER;
      if OpenKey('Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION', true) then
        WriteInteger(ExtractFileName(Application.ExeName), 8888);
    finally
      Free;
    end;

  WebBrowser1.Navigate('http://docwiki.embarcadero.com/RADStudio/en/Main_Page');
end;

The values are 8000, 7000, and 8888 for "IE8 Standards Mode", "IE7 Standards Mode", and "IE8 Standards Mode (Forced)", respectively. Hence, the above code will force IE8 standards mode.

Surprisingly, however, setting the mode to standard will only make the font even larger.

Andreas Rejbrand
Andreas, thanks for your comment about the `compatibility mode`, but why some pages looks with the same style and font when they run in `compatibility mode` ?
Salvador
A: 

I normally fix this by setting the ZOOM:

WebBrowser1.ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, zoom);

You need to use OLECMDID_GETZOOMRANGE to determine the valid ranges for zoom. Read the remarks on MSDN documentation for more information.

glob