Reputation: 423
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
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