我知道为时已晚,但我觉得我对这个问题有一个聪明的答案。
使用这个,它对我来说很有效。:)
webBrowser.ScriptErrorsSuppressed = true;
如果它不起作用,我们可以使用不同的方法,例如显示确认框(例如:此窗口要关闭,您要继续吗?是/否)
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
private void TimerPopUp_Tick(object sender, EventArgs e)
{
IntPtr hWnd1 = FindWindowByCaption(IntPtr.Zero, "Web Browser");
if (hWnd1 != IntPtr.Zero && SetForegroundWindow(hWnd1))
{
SendKeys.Send("{Enter}");
}
}
Run Code Online (Sandbox Code Playgroud)
如果有任何错误,请参阅此链接。