I have seen many articles or forums giving the following solution..but this solution is not going to work because after around 15 mins or sometimes after a few hours alert boxes will appear again, but I think timing is not an issue. I put this code inside a WebBrowserDocumentCompletedEventHandler.
And then I tried the following: Create a infinite loop and check it every second, if does not contain window.alert = function () { } then add it again, this is to prevent the website got ajax remove the code I injected earlier.
window.alert = function () { }
It still fails. My system has 5 tabs, each tab has its own web browser. I do injected each browser upon complete loaded.
private void InjectAlertBlocker() { HtmlElement head = webBrowser1.Document.GetElementsByTagName("head")[0]; HtmlElement scriptEl = webBrowser1.Document.CreateElement("script"); IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement; string alertBlocker = "window.alert = function () { }"; element.text = alertBlocker; head.AppendChild(scriptEl); }