AymAn AbuOmar
AymAn AbuOmar

Reputation: 423

How to get alerts message instead of showing it as message box ? webbrowser control

I am looking for a way to get the string of JavaScript alerts messages instead of showing it as message box,now, I am using a code to block alerts form a web page, this is the code (c#):

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);

I have this in web browser control navigated event.

I am very new to JavaScript that's why :)

Thank you very much.

Upvotes: 0

Views: 1077

Answers (1)

eventHandler
eventHandler

Reputation: 1211

string alertBlocker = "window.alert = function (msg) {document.write(msg);}";

there you can write the message to a hidden div/span/etc and then get that hidden div's innerText.

Upvotes: 1

Related Questions