Question

Currently I am using the following code but it is not working:

private void InjectAlertBlocker()
{
    string alertBlocker = @"window.alert = function () { }; 
                            window.print = function () { }; 
                            window.open = function () { }; 
                            window.onunload = function () { }; 
                            window.onbeforeunload = function () { };";

    webBrowser1.Document.InvokeScript("execScript", 
                                      new Object[] { alertBlocker, "JavaScript" });
}

http://www.ehrs.info/h/blea.php

It blocks the alert if you click on 'Test' but not if you navigate away or refresh.

How to completely block this function?

Was it helpful?

Solution

I managed to solve it by injecting the alert blocker on the ProgressChanged event instead of DocumentCompleted.

private void webBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
    {
        InjectAlertBlocker();
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top