GeckoFX浏览器的属性Enabled
确定整个浏览器是否可以获取输入。
但是,如果将其放置为false
,则滚动条将根本无法单击或拖动。
我正在寻找一种禁用整个浏览器而不禁用滚动条的方法,简单来说,就是禁用所有内容,防止它们从表单获取输入。
答案 0 :(得分:1)
我看到许多路线:而不是geckowebbrowser.Enabled = false;
disable所有input
,select
,textarea
,button
以及DOM上的链接,例如
GeckoElementCollection byTag = _browser.Document.GetElementsByTagName("input");
foreach (var ele in byTag)
{
var input = ele as GeckoInputElement;
input.Disabled = true;
}
等。
从可点击元素中删除指针事件,例如
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;");
}
使用不可见的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/");
}
}
}
OnClick
事件,并将事件设置为e.Handled = true;
当然还有其他选择。