停止 webbrowser C# 控件中的警报 javascript 弹出窗口

发布于 2024-09-26 01:14:24 字数 393 浏览 5 评论 0原文

这个网站: http://blog.joins.com/media /folderListSlide.asp?uid=ddatk&folder=3&list_id=9960150

有这样的代码:

<script>alert('¿Ã¹Ù¸¥ Çü½ÄÀÌ ¾Æ´Õ´Ï´Ù.');</script>

所以我的网络浏览器控件显示一个弹出窗口,如何在不使用 sendkeys Enter 的情况下绕过弹出窗口?

This website :
http://blog.joins.com/media/folderListSlide.asp?uid=ddatk&folder=3&list_id=9960150

has this code:

<script>alert('¿Ã¹Ù¸¥ Çü½ÄÀÌ ¾Æ´Õ´Ï´Ù.');</script>

So my web browser control show a popup, how can I bypass the popup without using sendkeys enter??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

ま柒月 2024-10-03 01:14:24

如果您不打算在页面上使用 alert() 函数,您也可以覆盖它。例如:

<script type="text/javascript">
alert = function(){}
</script>

如果你确实需要使用 JavaScript 的警报功能,你可以“重载”它:

<script type="text/javascript">
var fnAlert = alert;
alert = function(message,doshow) {
    if (doshow === true) {
        fnAlert(message);
    }
}
alert("You won't see this");
alert("You will see this",true);
</script>

If you intend not to ever use the alert() function on your page, you can also just override it. E.g.:

<script type="text/javascript">
alert = function(){}
</script>

If you do need to use JavaScript's alert function, you can 'overload' it:

<script type="text/javascript">
var fnAlert = alert;
alert = function(message,doshow) {
    if (doshow === true) {
        fnAlert(message);
    }
}
alert("You won't see this");
alert("You will see this",true);
</script>
聊慰 2024-10-03 01:14:24

ProgressChanged 事件处理程序中,您插入一个脚本元素,用您自己的函数替换 Javascript alert 函数,该函数不执行任何

private void webBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
    {
        if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
        {
            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);
        }
    }

操作:为此,您需要在表单中添加对 Microsoft.mshtmluse mshtml; 的引用。

In the ProgressChanged event handler, you insert a script element that replaces the Javascript alert function with a function of your own, that does nothing:

private void webBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
    {
        if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
        {
            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);
        }
    }

For this to work, you need to add a reference to Microsoft.mshtml and use mshtml; in your form.

假情假意假温柔 2024-10-03 01:14:24

处理 IDocHostShowUI::ShowMessage 并返回 S_OK。
检查http://www.codeproject.com/KB/miscctrl/csEXWB.aspx 举个例子。

handle IDocHostShowUI::ShowMessage and return S_OK.
Check http://www.codeproject.com/KB/miscctrl/csEXWB.aspx for an example.

灯下孤影 2024-10-03 01:14:24

给出的解决方案是错误的

private void webBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
{
    if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
    {
        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);
    }
}

似乎处理消息的 Windows 挂钩是解决方案

solution given is wrong

private void webBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
{
    if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
    {
        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);
    }
}

Seems handling a windows hook for message is solution

巷雨优美回忆 2024-10-03 01:14:24

我认为您正在 WinForm 应用程序中使用 WebBroswer 在 JavaScript 中的 alert(xxx) 内导航页面?您可以尝试:

broswer.Navigated += (sender, args) =>
  {
     var document = (sender as WebBrowser).DocumentText;
     //find the alert scripts and remove/replace them
  }

I think you are navigating a page within alert(xxx) in its javascript using WebBroswer in a WinForm application? You can try:

broswer.Navigated += (sender, args) =>
  {
     var document = (sender as WebBrowser).DocumentText;
     //find the alert scripts and remove/replace them
  }
煞人兵器 2024-10-03 01:14:24

您可以通过设置禁用所有弹出窗口,

webBrowser.ScriptErrorsSuppressed = true;

尽管名称如此,此设置实际上会阻止所有弹出窗口,包括alert()

You can disable all popups by setting

webBrowser.ScriptErrorsSuppressed = true;

Despite the name, this settings actually blocks all popups, including alert()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文