简体   繁体   English

如何获取警报消息而不是将其显示为消息框? 网络浏览器控件

[英]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#): 我正在寻找一种获取JavaScript警报消息字符串的方法,而不是将其显示为消息框,现在,我正在使用代码来阻止来自网页的警报,这是代码(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. 我在Web浏览器控件的导航事件中具有此功能。

I am very new to JavaScript that's why :) 我对JavaScript非常陌生,这就是原因:)

Thank you very much. 非常感谢你。

string alertBlocker = "window.alert = function (msg) {document.write(msg);}"; 字符串alertBlocker =“ window.alert =函数(msg){document.write(msg);}”;

there you can write the message to a hidden div/span/etc and then get that hidden div's innerText. 在那里,您可以将消息写入隐藏的div / span / etc,然后获取该隐藏的div的innerText。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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