GeckoFX在保持滚动条的同时禁用表单输入

问题描述 投票:1回答:1

GeckoFX浏览器的属性Enabled确定整个浏览器是否可以获取输入。

但是,如果它被放置为false,则滚动条无法单击或拖动。

我正在寻找一种方法来禁用整个浏览器而不禁用滚动条,简单来说,禁用所有内容,防止它们从表单获取输入。

c# geckofx window-handles
1个回答
1
投票

我看到了许多路线:而不是geckowebbrowser.Enabled = false;

  1. disable所有inputselecttextareabutton以及DOM上的链接,例如 GeckoElementCollection byTag = _browser.Document.GetElementsByTagName("input"); foreach (var ele in byTag) { var input = ele as GeckoInputElement; input.Disabled = true; } 等等..
  2. 从可点击元素中删除指针事件,例如 var byTag = _browser.Document.GetElementsByTagName("a"); foreach (var ele in byTag) { var a = ele as GeckoHtmlElement; //a.SetAttribute("disabled", @"true"); a.SetAttribute("style", "pointer-events: none;cursor: default;"); }
  3. 使用不可见的CSS阻止覆盖(jsfiddle),例如使用JavaScript

//UI block
window.onload = function() {        
    var blockUI = document.createElement("div");
    blockUI.setAttribute("id", "blocker");
    blockUI.innerHTML = '<div></div>'
    document.body.appendChild(blockUI);
    
    //unblock it
    //var cover = document.getElementById("blocker").style.display = "none";
}
#blocker
{
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.0;
    background-color: #111;
    z-index: 9000;
    overflow: auto;
}
<button id="bloc">Blocked UI</button>

在我的WPF demo应用程序的代码隐藏中,我在DocumentCompleted事件中完成加载页面后附加叠加层:

using Gecko;
using Gecko.DOM;
using System.Windows;
using System.Windows.Forms.Integration;
using System.Linq;    
namespace GeckoWpf {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
            Gecko.Xpcom.Initialize("Firefox");
        }    
        void browser_DocumentCompleted(object sender, System.EventArgs e) {
             //unsubscribe
            _browser.DocumentCompleted -= browser_DocumentCompleted;

            GeckoElement rt = _browser.Document.CreateElement("div");
            rt.SetAttribute("id", "blocker");
            rt.SetAttribute
            (
            "style",
            "position: fixed;"
            + "top: 0px;"
            + "left: 0px;"
            + "width: 100%;"
            + "height: 100%;"
            + "opacity: 0.0;"
            + "background-color: #111;"
            + "z-index: 9000;"
            + "overflow: auto;"
            );
            _browser.Document.Body.AppendChild(rt);
        }    
        WindowsFormsHost _host = new WindowsFormsHost();
        GeckoWebBrowser _browser = new GeckoWebBrowser();    
        private void Window_Loaded(object sender, RoutedEventArgs e) {
            _browser.DocumentCompleted += browser_DocumentCompleted;
            _host.Child = _browser;
            GridWeb.Children.Add(_host);    
            _browser.Navigate("https://www.google.com/");
        }
    }
}
  1. 覆盖主应用程序窗口或Gecko Dom事件中的OnClick事件,并将事件设置为e.Handled = true;

当然还有其他选择。

© www.soinside.com 2019 - 2024. All rights reserved.