I'm trying to remove the scrollbars and border from a TWebBrowser. I've found loads of references to the following code and it works fine when used on www.google.com:
// Switch off scrollbars
WB.OleObject.document.body.style.overflowX := 'hidden';
WB.OleObject.document.body.style.overflowY := 'hidden';
// Switch off borders
WB.OleObject.document.body.style.borderstyle := 'none';
However, using a web page generated by ASP.NET, it no longer works.
Here's the ASP.NET aspx code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test</title>
</head>
<body bgcolor="#333333" border="0">
<form id="form1" runat="server">
<table style="width:100%;">
<tr>
<td class="style7">
<asp:Label ID="Label2" runat="server" Font-Names="Arial" Font-Size="21pt"
ForeColor="#F2F2F2" Text="Test"></asp:Label>
</td>
</tr>
</table>
</form>
</body>
</html>
...and here's the HTML generated by the ASP.NET application:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
Test
</title></head>
<body bgcolor="#333333" border="0">
<form method="post" action="Default.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJODExMDE5NzY5ZGSKCPuFcF0SPBHrn5HUkzHPVjgZoCXwtqbgbPjoAyOPAQ==" />
</div>
<table style="width:100%;">
<tr>
<td class="style7">
<span id="Label2" style="color:#F2F2F2;font-family:Arial;font-size:21pt;">Test</span>
</td>
</tr>
</table>
</form>
</body>
</html>
Any idea why the scrollbars/borders are still visible?
As you say it works before and you have put a tag internet-explorer-11
, I think the problem is more or less related to page rendering policy. So the solution could be FEATURE_BROWSER_EMULATION
. Can you confirm that the problem occurs with MSIE11 only?
In case of FEATURE_BROWSER_EMULATION
, you should add an entry into Registry with the application name as key. The value should be a corresponding emulation flag. For better troubleshooting, please paste related code.
Here is my proven code that can change rendering policy for your application. You can give a try.
const
BROWSER_EMULATION_MSIE11_FORCED = 11001;
BROWSER_EMULATION_MSIE11 = 11000; // currently this is the best rendering engine we can have
BROWSER_EMULATION_MSIE10_FORCED = 10001;
BROWSER_EMULATION_MSIE10 = 10000;
BROWSER_EMULATION_MSIE9_FORCED = 9999;
BROWSER_EMULATION_MSIE9 = 9000;
BROWSER_EMULATION_MSIE8_FORCED = 8888;
BROWSER_EMULATION_MSIE8 = 8000;
BROWSER_EMULATION_MSIE7 = 7000;
procedure SetBrowserEmulation(Value: Integer; const ExeName: string);
begin
ChangeFeatureControlRegValue('FEATURE_BROWSER_EMULATION', ExeName, Value);
end;
procedure ChangeFeatureControlRegValue(const Feature, ExeName: string; Value: Integer);
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
if Reg.OpenKey('\Software\Microsoft\Internet Explorer\Main\FeatureControl\' + Feature, {CanCreate=}True) then
begin
try
Reg.WriteInteger(ExeName, Emulation);
finally
Reg.CloseKey;
end;
end;
finally
Reg.Free;
end;
end;
As a small promotion, you can use my dutil.sys.win32.registry.Writer to simplify the whole Registry accessing stuff.
procedure ChangeFeatureControlRegValue(const Feature, ExeName: string; Value: Integer);
begin
TWriter.WriteUInt('\Software\Microsoft\Internet Explorer\Main\FeatureControl\' + Feature, ExeName, Value);
end;
A different approach is to override browser behaviour. Have you ever tried to implement IDocHostUIHandler
and override IDocHostUIHandler::GetHostInfo
. If you have tried the famous TEmbeddedWB
component, you will find demo code of how to implement IDocHostUIHandler
. The key thing is to set pInfo.dwFlags
to include flag DOCHOSTUIFLAG_SCROLL_NO
.