简体   繁体   English

如何在c#WebBrowser控件中禁止显示“停止运行此脚本”提示?

[英]How to suppress the 'stop running this script' prompt in the c# WebBrowser control?

I have a WebBrowser control inside a C# dialog that calls a C# function from JavaScript (via an HTML button). 我在C#对话框中有一个WebBrowser控件,该控件从JavaScript(通过HTML按钮)调用C#函数。 This sets off a fairly lengthy operation in C# code. 这在C#代码中引发了相当长的操作。 Ideally, I would like the user to be able to leave it to continue unattended. 理想情况下,我希望用户能够使其继续无人看管。 Unfortunately since it's kicked off from JavaScript it's periodically interrupted by the following prompt, requiring the user to make a yes/no selection before it will continue: 不幸的是,由于它是从JavaScript开始的,因此会定期被以下提示打断,要求用户选择是/否,然后才能继续:

Stop running this script? 停止运行此脚本?

A script on this page is causing your web browser to run slowly. 此页面上的脚本导致您的Web浏览器运行缓慢。 If it continues to run, your computer might become unresponsive. 如果继续运行,则您的计算机可能无响应。

Is there any way to suppress this message in the control so that it can continue uninterrupted? 有什么方法可以抑制控件中的此消息,使其可以不间断地继续运行? I've tried setting ScriptErrorsSuppressed to true but it doesn't seem to work for this particular message. 我尝试将ScriptErrorsSuppressed设置为true,但似乎不适用于此特定消息。

You're seeing that message because Javascript is waiting for the function to return, and execution is sitting in the C# side during your lengthy operation. 您看到该消息的原因是Javascript正在等待函数返回,而在执行冗长的操作期间,执行位于C#端。

When the user hits the button, have C# kick off the operation using Dispatcher.BeginInvoke (msdn) or a BackgroundWorker (msdn) . 当用户按下按钮时,请使用Dispatcher.BeginInvoke (msdn)BackgroundWorker (msdn)使C#启动该操作。 While the operation is running, execution can return to the Javascript. 在操作运行时,执行可以返回到Javascript。 Then have the C# tell the Javascript when the job is done. 然后让C#告诉Java作业何时完成。

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

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