The following sample demonstrates how to customize the JavaScript Alert dialog by registering custom DialogHandler implementation. Using the same technique you can override other dialogs such as JavaScript Confirmation, Prompt, Before Unload, Reload POST data, File Open/Save dialogs, etc.

The DialogHandler is responsible for displaying the JavaScript dialogs like alert or prompt, so your custom implementation can be used to disable them completely.


Form1.cs


using DotNetBrowser;
using DotNetBrowser.WinForms;
using System;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinForms.CustomDialogsSample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            // Initialize BrowserView
            var browser = BrowserFactory.Create();
            BrowserView browserView = new WinFormsBrowserView(browser);
            Controls.Add((Control)browserView);

            browser.DialogHandler = new CustomDialogHandler((Control)browserView, WindowsFormsSynchronizationContext.Current);
            
            browser.LoadHTML("<html><body><p>Click the button to display an alert box.</p><button onclick='myFunction()'>Try it</button><script>function myFunction() { alert('Hello! I am an alert box!');}</script></body></html>");
        }
    }
}


CustomDialogHandler.cs 


using DotNetBrowser;
using DotNetBrowser.WinForms;
using System;
using System.Threading;
using System.Windows.Forms;

namespace WinForms.CustomDialogsSample
{
    class CustomDialogHandler : DialogHandler
    {
        private WinFormsDefaultDialogHandler handler;
        private Control control;
        private SynchronizationContext synchronizationContext;

        public CustomDialogHandler(Control control,System.Threading.SynchronizationContext synchronizationContext)
        {
            this.control = control;
            this.synchronizationContext = synchronizationContext;
            handler = new WinFormsDefaultDialogHandler(control);
        }

        public void OnAlert(DialogParams parameters)
        {
            synchronizationContext.Send(new SendOrPostCallback(
               delegate(object state)
               {
                   String url = parameters.Url;
                   String title = "Message from \"" + url + "\"";
                   String message = parameters.Message;
                   MessageBox.Show(control, message, title);
               }), parameters);
        }

        public CloseStatus OnBeforeUnload(UnloadDialogParams parameters)
        {
            return handler.OnBeforeUnload(parameters);
        }

        public CloseStatus OnConfirmation(DialogParams parameters)
        {
            return handler.OnConfirmation(parameters);
        }

        public CloseStatus OnFileChooser(FileChooserParams parameters)
        {
            return handler.OnFileChooser(parameters);
        }

        public CloseStatus OnPrompt(PromptDialogParams parameters)
        {
            return handler.OnPrompt(parameters);
        }

        public CloseStatus OnReloadPostData(ReloadPostDataParams parameters)
        {
            return handler.OnReloadPostData(parameters);
        }

        public CloseStatus OnSelectCertificate(CertificatesDialogParams parameters)
        {
            return handler.OnSelectCertificate(parameters);
        }
    }
}