GeckoFX浏览器的属性Enabled
确定整个浏览器是否可以获取输入。
但是,如果它被放置为false
,则滚动条无法单击或拖动。
我正在寻找一种方法来禁用整个浏览器而不禁用滚动条,简单来说,禁用所有内容,防止它们从表单获取输入。
我看到了许多路线:而不是geckowebbrowser.Enabled = false;
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;");
}
//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;
当然还有其他选择。