delphi去除webbrowser滚动条的正确方法(流传的都不对)

今天乱翻论坛,回答了一个网友的问题。

http://topic.csdn.net/u/20101006/08/a372ebf1-838e-4653-a7f7-517fac560f47.html?seed=140121506&r=69102800#r_69102800

网上给出的东西好些都不准确啊,今天在这里记下来,省的以后忘掉。

网上流传的去掉滚动条的方法是:

Wb1.OleObject.Document.Body.style.border := 'none';

或者

Wb1.OleObject.Document.Body.style.border := 'no';

这两条都是不对的。

首先,第一条会报错,属性设置错误。只有3种:

yes

no

aotu

原文说明如下:

sScrollString thatspecifies or receives one of the following values.

yes
Default. Scroll bars are turned on.
no
Scroll bars are turned off.
auto
Scroll bars are shown when the page content exceeds the client area.

The property is read/write.The property has a default value of yes.

DHTML expressions can be used in place of the preceding value(s). As of Internet Explorer 8, expressions are not supported in IE8 mode. For more information, see About Dynamic Properties.

Remarks

With Microsoft Internet Explorer 6 and later, when you use the !DOCTYPE declaration to specify standards-compliant mode, this attribute applies to the HTML element. When standards-compliant mode is not specified, as with earlier versions of Windows Internet Explorer, this attribute applies to the BODY element, not the HTML element

懒得翻译,反正是delphi用不了这个方法,也没有上js测试。

我记得以前好像有一个style属性来着,找了找,加上:

    WB1.oleobject.Document.body.Scroll := 'hidden';

这样一来,下面的滚动条没有了,右面还有一个。仔细想了一下,发现里面有个问题,body的大小和twebbrowser的大小本来就是两个概念,仅仅设置hidden了,body的大小还是没有改变,里面不知道那里又出来一个滚动条,改动了一下body的大小:

    WB1.oleobject.Document.body.style.width:= '200px';
    WB1.oleobject.Document.body.style.height:= '300px' ;

于是这次成功了。不过不完善,还有一个灰色的边框啊!

 

void CMFCReproDlg::OnBeforeNavigate2Explorer1(LPDISPATCH pDisp, VARIANT FAR* URL, VARIANT FAR* Flags, VARIANT FAR*

TargetFrameName, VARIANT FAR* PostData, VARIANT FAR* Headers, BOOL FAR* Cancel)
{
    static int nCount = 0;

    nCount++;
    if (nCount == 2) // this should be the navigate for the first frame in frameset
    {
        IWebBrowser* pWB = NULL;
        HRESULT hr = pDisp->QueryInterface(IID_IWebBrowser, (void**)&pWB);
        COleVariant ve((long)0);
        pWB->Navigate(::SysAllocString(L"http://myserver/mydirectory/framesetChild.htm"), &ve, &ve, &ve, &ve);
        *Cancel = VARIANT_TRUE;
    }
}
//以下是附录
Visual C 5.0 uuid.lib不包含IID_IWebBrowser和CLSID_WebBrowser的定义,
但是二者的 ID很容易在exdisp.h中找到,我从中提出它们:
/* EAB22AC1-30C1-11CF-A7EB-0000C05BAE0B */
IID const IID_IWebBrowser={0xEAB22AC1, 0x30C1, 0x11CF, 0xA7, 0xEB, 0x00, 0x00, 0xC0, 0x5B, 0xAE, 0x0B};
 /* 8856F961-340A-11D0-A96B-00C04FD705A2 */
CLSID const CLSID_WebBrowser={0x8856F961, 0x340A, 0x11D0, 0xA9, 0x6B, 0x00, 0xC0, 0x4F, 0xD7, 0x05, 0xA2};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值