当页面加载时,滚动条显示在web浏览器中

时间:2022-08-24 17:41:40

Edit: I changed the property to Hidden, but it still shows up.

编辑:我将属性更改为Hidden,但它仍然显示出来。

I have read about 10 different variations of this problem and all of them seem to have a different solution none of which work for me.

我读过关于这个问题的10种不同的变体,它们似乎都有不同的解决方案,但没有一种对我有效。

I have a WPF Window with a WebBrowser as shown below (as you can see I have been very thorough in trying to make sure the vertical scroll bar is hidden):

我有一个WPF窗口和一个WebBrowser,如下所示(正如你所看到的,我已经非常彻底地试图确保垂直滚动条是隐藏的):

<Window x:Class="ZendeskWebApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="460" Width="700" ScrollViewer.VerticalScrollBarVisibility="Hidden">
    <Grid ScrollViewer.VerticalScrollBarVisibility="Hidden">
        <WebBrowser Name="_browser" ScrollViewer.VerticalScrollBarVisibility="Hidden"/>
    </Grid>
</Window>

In the code behind I am loading a local html page:

在后面的代码中,我正在加载一个本地html页面:

public MainWindow()
{
    InitializeComponent();
    this._browser.Source = new Uri(new System.IO.FileInfo("AskAQuestion.htm").FullName);
}

This is the only content on the page:

这是页面上唯一的内容:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <title>Ask A Question</title>
    </head>
        <body>
            <div>
                <iframe src="http://mysite.zendesk.com/account/dropboxes/123456" width="100%" height="100%" frameborder=0></iframe>
            </div>
        </body>
    </html>

The only scrollbar that should be showing up is the iframe scrollbar, yet a vertical scrollbar loads whenever the page loads in the iframe. When there is no page loaded there is no scrollbar.

应该显示的唯一滚动条是iframe scrollbar,但无论何时在iframe中加载页面,都会加载垂直滚动条。当没有加载页面时,就没有滚动条。

Why is this happening?

为什么会这样?

2 个解决方案

#1


0  

Have you tried this combination of settings on your WebBrowser object?

您是否尝试过在您的WebBrowser对象上使用这些设置组合?

ScrollViewer.CanContentScroll="False"
ScrollViewer.HorizontalScrollBarVisibility="Hidden" 
ScrollViewer.VerticalScrollBarVisibility="Hidden" />

#2


0  

This solution worked for me:

这个解决方案对我起了作用:

XAML:

XAML:

<WebBrowser Name="MyWebBrowser" LoadCompleted="WebBrowserOnLoadCompleted">


CodeBehind:

后台代码:

private void WebBrowserOnLoadCompleted(object sender, NavigationEventArgs e)
{
    HideScrollbars(MyWebBrowser);
}

private void HideScrollbars(WebBrowser wb)
{
    const string script = "document.body.style.overflow ='hidden'";
    wb.InvokeScript("execScript", new Object[] { script, "JavaScript" });
}

#1


0  

Have you tried this combination of settings on your WebBrowser object?

您是否尝试过在您的WebBrowser对象上使用这些设置组合?

ScrollViewer.CanContentScroll="False"
ScrollViewer.HorizontalScrollBarVisibility="Hidden" 
ScrollViewer.VerticalScrollBarVisibility="Hidden" />

#2


0  

This solution worked for me:

这个解决方案对我起了作用:

XAML:

XAML:

<WebBrowser Name="MyWebBrowser" LoadCompleted="WebBrowserOnLoadCompleted">


CodeBehind:

后台代码:

private void WebBrowserOnLoadCompleted(object sender, NavigationEventArgs e)
{
    HideScrollbars(MyWebBrowser);
}

private void HideScrollbars(WebBrowser wb)
{
    const string script = "document.body.style.overflow ='hidden'";
    wb.InvokeScript("execScript", new Object[] { script, "JavaScript" });
}