简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM