Reputation: 399
The property Enabled
of a GeckoFX browser determines if the whole browser can get inputs or not.
However, if it's placed as false
then the scrollbars are being unable to click on or dragged at all.
I'm looking for a way to disable the whole browser without disabling the scrollbars, in simple terms, to disable all the content, prevent them from getting inputs from a form.
Upvotes: 1
Views: 586
Reputation: 18950
I see a number of routes: Instead of geckowebbrowser.Enabled = false;
disable all input
, select
, textarea
, button
, and links on the DOM e.g.
GeckoElementCollection byTag = _browser.Document.GetElementsByTagName("input");
foreach (var ele in byTag)
{
var input = ele as GeckoInputElement;
input.Disabled = true;
}
etc..
remove the pointer events from clickable elements, e.g.
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;");
}
Use an invisible CSS blocker overlay (jsfiddle), e.g. using 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>
In the code-behind of my WPF demo app I append the overlay after the page has finished loading in the DocumentCompleted event:
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
event in your main application window or the Gecko Dom Events and set the event to e.Handled = true;
There are certainly other options as well.
Upvotes: 1